Configure Static Routes in Debian or Red Hat Enterprise Linux
Configure Static Routes in Debian or Red Hat Enterprise Linux
Configure Static Routes in Debian or Red Hat Enterprise Linux
Static routes improves overall performance of your network (especially bandwidth saving).
They are also useful in stub networks (i.e. there is only one link to the network). For example,
each LAN (located at different offices) is connected to HQ IDC (Internet data center) using
single T1/LL/Wan links.
For example under Red Hat/Fedora Linux you can add static router for eth0 network interface
by editing /etc/sysconfig/network-scripts/route-eth0 file. Under Debian Linux add static route
by editing /etc/network/interface file.
You need to open /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0
interface:
# cat /etc/sysconfig/network-scripts/route-eth0
Sample Output:
GATEWAY0=192.168.1.254
NETMASK0=255.255.255.0
ADDRESS0=192.168.55.0
GATEWAY1=10.164.234.112
NETMASK1= 255.255.255.240
ADDRESS1=10.164.234.132
How do I define static routing for network 10.0.0.0/8 via 10.9.38.65 router?
Open /etc/sysconfig/network-scripts/route-eth0:
# vi /etc/sysconfig/network-scripts/route-eth0
Append following line:
10.0.0.0/8 via 10.9.38.65
Save and close the file. Restart networking:
# service network restart
Verify new routing table:
# route -n
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.254
up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1
down route del -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.9.38.76
netmask 255.255.255.240
network 10.9.38.64
broadcast 10.9.38.79
### static routing ###
post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65
pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65
auto eth1
iface eth1 inet static
address 204.186.149.140
netmask 255.255.255.240
network 204.186.149.128
broadcast 204.186.149.143
gateway 204.186.149.129
# dns-* options are implemented by the resolvconf package, if
installed
dns-nameservers 10.0.80.11 10.0.80.12
dns-search nixcraft.in