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 connecting to HQ IDC (internet data center) using single T1/LL/Wan link.
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.
Use of ip command
By using the ip command, you can setup static route. For example, to display current routing table you can type command:# ip route showOutput:
192.168.2.0/24 dev eth1 proto kernel scope link src 192.168.2.1
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.2
default via 192.168.1.254 dev eth0
You can add static route using following command:
ip route add {NETWORK} via {IP} dev {DEVICE}
For example network 192.168.55.0/24 available via 192.168.1.254:# ip route add 192.168.55.0/24 via 192.168.1.254 dev eth1Alternatively, use old good route command:# route add -net 192.168.55.0 netmask 255.255.255.0 gw 192.168.1.254 dev eth1The drawback of ‘ip’ or ‘route’ command is that, when Linux reboots it will forget static routes. So store them in configuration file.
Red Hat/Fedora Linux Static route file
path: /etc/sysconfig/network-scripts/route-eth0
# cat /etc/sysconfig/network-scripts/route-eth0 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
Debian Linux static routes file
# cat /etc/network/interfaceOutput:
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
Updated for accuracy.