persistent static routes linux debian

Notes on Persistent static routes debian on /etc/network/interfaces when a routing daemon is not used.

default gateway --the 0.0.0.0/0 route is set with gateway eg.
auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 192.0.2.222
        netmask 255.255.255.0
        network 192.0.2.0
        broadcast 192.0.2.255
        gateway 192.0.2.1


Some other route is set with up and unset with down eg: for the 10.0.0.0/8 route
auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
 address 10.21.241.34
 netmask 255.255.255.128
 network 10.21.241.0
 broadcast 10.21.241.127
 up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.21.241.69
 down route del -net 10.0.0.0 netmask 255.0.0.0 gw 10.21.241.69


An example /etc/network/interfaces
# cat /etc/network/interfaces 
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 192.0.2.222
        netmask 255.255.255.0
        network 192.0.2.0
        broadcast 192.0.2.255
        gateway 192.0.2.1

auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
 address 10.21.241.34
 netmask 255.255.255.128
 network 10.21.241.0
 broadcast 10.21.241.127
 up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.21.241.69
 down route del -net 10.0.0.0 netmask 255.0.0.0 gw 10.21.241.69


The above /etc/network/interfaces produces the following routing table
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.0.2.1       0.0.0.0         UG    0      0        0 eth0
10.0.0.0        10.21.241.69    255.0.0.0       UG    0      0        0 eth0
10.21.241.0     0.0.0.0         255.255.255.128 U     0      0        0 eth0
192.0.2.0       0.0.0.0         255.255.255.0 U     0      0        0 eth0


URI: http://alog.ipduh.com/2013/01/static-routes-linux-debian.html



Persistent Static Routes Linux Debian