I have 2 network interfaces on my CentOS 7 Minimal box.I need to setup policy based routing, so that if a request comes in on one interface, the reply gets sent out the same interface.Doing this with iproute2 in a non-persistent way is not terribly difficult:echo '200 isp2' >> /etc/iproute2/rt_tablesip route add default via 1.1.1.1 table isp2ip rule add from 192.168.1.50 table isp2Where 1.1.1.1 is my router, and 192.168.1.50 is my linux's IP.The problem is making this persistent.From what I've read, there's no iproute2 persistence file - the way to make things persistent is to add them to your network startup scripts.Normally, RedHat recommends creating the file /etc/sysconfig/network-scripts/route-ethX to add routes, but this does not appear to be able to add routes to a secondary routing table.The solution seems to be to add the ip route and ip rule lines from above to /etc/sysconfig/network instead. This almost works, except for one thing: Every time the network is restarted, it keeps adding duplicate ip rule rules, dozens at a time.After restarting my network 2 or 3 times with systemctl restart network, my ip rule output looks like this:0: from all lookup local32670: from 192.168.1.50 lookup isp232671: from 192.168.1.50 lookup isp2...32764: from 192.168.1.50 lookup isp232765: from 192.168.1.50 lookup isp232766: from all lookup main32767: from all lookup defaultWhat is the proper way to add persistent policy-based-routing rules on CentOS 7?PS. The ip route list table isp2 command shows a single entry, as expected, so that's not a problem.Edit: According to the RedHat 7 manual:in Red Hat Enterprise Linux the use of the global /etc/sysconfig/network file is deprecatedThis is in favour of interface-specific config files, which don't appear to be able to add routes to a different routing table, and can't add ip rule rules.
How do I create CentOS 7 Persistent Policy-Based-Routing Rules?
centos;networking
Installing NetworkManager-config-routing-rules, and enabling NetworkManager-dispatcher seems to have fixed it:$ sudo yum install NetworkManager-config-routing-rules$ sudo systemctl enable NetworkManager-dispatcher.service$ sudo systemctl start NetworkManager-dispatcher.serviceNow I can have this in my /etc/sysconfig/network-scripts/route-ethX:default via 1.1.1.1 table isp2And this in my /etc/sysconfig/network/scripts/rule-ethX:from 192.168.1.50 table isp2And a definition for isp2 in my /etc/iproute2/rt_tables:200 isp2Restarting the network service no longer creates duplicate entries.