I have modified my routing table by deleting one rule, and adding two new rules for my second interface eth1:

route del -net netmask
route add -host eth1
route add -host eth1

I want the rules to survive reboot. I could write a simple rc script to remove 1 rule and insert 2 new, but I was wondering whether there is a way to configure ifconfig, not to add a route rule for the interface (eth1) when it is started, or even better, to specify which rules should be added.

What would be a clean way to do it? Does ifconfig allow me to specify custom rules for routing?

1 Answer 1


You can add the calls to the post-up hook when the interface comes up. The interface configuration sits in /etc/network/interfaces. Here an example:

auto eth1
iface eth1 inet dhcp
  post-up route del -net netmask
  post-up route add -host eth1
  post-up route add -host eth1
  pre-down route add -net netmask
  pre-down route add -host eth1
  pre-down route add -host eth1

From the man page - interfaces:

post-up command
Run command after bringing the interface up. If this command fails then ifup aborts, refraining from marking the interface as configured (even though it has really been configured), prints an error message, and exits with status 0.

pre-down command
Run command before taking the interface down. If this command fails then ifdown aborts, marks the interface as deconfigured (even though it has not really been deconfigured), and exits with status 0.

Furthermore, on Linux the “net-tools” route is deprecated and should be replaced by the tools from the iproute2 package.

Further reading:

  • could I, instead of removing the first rule, prevent it from being created in the first place? How does a route rule get created, anyway? From the network settings in /etc/network/interfaces? And how do I know, that when post-up runs, the rule-to-be-removed already exists? The man page does not say at what point in time it's created. Commented Jul 26, 2013 at 20:40
  • 1
    Since I neither know your network nor your host configuration, I can't tell how this route made it's way into the routing table. Does it come with a DHCP lease? If not, check your services in /etc/init.d and investigate which ones possibly could tinker with the routing table. Also have a look into /etc/network including subdirectories.
    – Marco
    Commented Jul 26, 2013 at 20:49
  • 5
    post-up and pre-down are aliases for up and down, respectively. And adding a || : at the end of a line allows the command to fail and not disturb ifup/ifdown. I usually add this to route del, in case the route does not exist yet and hence cannot be removed.
    – Tino
    Commented Feb 22, 2015 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .