How can I configure a persistent ip rule
on Linux (specifically Redhat based distros)? Is there no built in method? Is my only option adding to /etc/rc.d/rc.local
or creating my own rc.d
script?
Edit: For clarification I am not referring to iptables
but the ip
tool (which I don't think a lot of people are familiar with). In any case, the rule I am trying to persist is added with the following command:
# ip rule add fwmark 1 lookup 100
# ip rule
...
32765: from all fwmark 0x1 lookup 100
...
The only reference I've found to doing this is from Novell: http://www.novell.com/support/viewContent.do?externalId=7008874&sliceId=1 which recommends creating an rc.d
script
As is customary I stumble upon the answer to my own problem shortly after asking :) Found an answer at http://grokbase.com/t/centos/centos/099bmc07mq/persisting-iproute2-routes-and-rules
On Redhat 5+ the
/etc/sysconfig/network-scripts/ifup-routes
script handlesrule-*
files. Relevant code below:Script for RHEL 6.5 (possibly older 6+):
The above is about 3/4 of the answer - the missing piece is how to format the /etc/sysconf/network-scripts/rule-ethX file. You also need to add the routing tables to /etc/iproute2/rt_tables:
And add the rule file /etc/sysconfig/network-scripts/rule-eth0:
Note that the table names must match, and are case sensitive.
note if you use priorities in these rule files for any of the rules, you have to use priorities for all the rules. Otherwise, the ones that don't have any priorities all get added to the priority 0 chain.