Adding Persistent Static Routes in Debian

Stumbled upon this just a while ago...

Adding a static Route in Debian can be easily done by using the command

route add -net netmask gw dev eth1

Here, the network is accessible through next hop exit interface eth1. However, the problem is that the system forgets the route if the network service restarts. Here's how the route can be made permanent -

# The primary network interface
auto eth1
allow-hotplug eth1
iface eth1 inet static

up route add -net netmask gw dev eth1
up route add -net netmask gw dev eth1

down route del -net netmask gw dev eth1
down route del -net netmask gw dev eth1

The route is would now be updated every time the network service is restarted. Works like a charm :)


  1. This command don't exist's in debian 6. How to install post-up command??

    1. It works for me in Debain 6. However, sometimes, I need to restart the Debian box. When the systems starts up, the routes are present. However, when "networking restart" is issued, the routes may fail to show in the kernel table. Explanation is provided below for your reference.


      When you comment out the stanza about eth1 in /etc/network/interfaces, NetworkManager takes over the interface. What could help is in fact the output from ifconfig and route -n when you boot with the /etc/network/interfaces in your original question and do not get any internet connection. Note that Network Manager and ifupdown (invoked when you “restart networking”) are two different components; ifupdown is the one that executes the instructions in /etc/network/interfaces, while Network Manager only reads it to prevent itself from taking over if you've set things up for ifupdown. – Gilles Nov 10 '10 at 18:23


Post a Comment