Saturday, December 3, 2011
11:19 AM

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 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.2 dev eth1

Here, the network 192.168.2.0 is accessible through next hop 192.168.1.2 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
    address 192.168.1.3
    netmask 255.255.255.0

up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.2 dev eth1
up route add -net 192.168.10.0 netmask 255.255.255.0 gw 192.168.1.2 dev eth1

down route del -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.2 dev eth1
down route del -net 192.168.10.0 netmask 255.255.255.0 gw 192.168.1.2 dev eth1

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

0 comments:

Post a Comment