Linux: Setting up a static route
Temporary: Linux add a default route using route command Route all traffic via 192.168.1.254 gateway connected via eth0 network interface: # route add default gw 192.168.1.254 eth0 Linux add a default gateway (route) using ip command Route all traffic via 192.168.1.254 gateway connected via eth0 network interface: # ip route add 192.168.1.0/24 dev eth0 Persistent: RHEL/CentOS/Fedora/Scientific Linux persistent routing configuration Edit /etc/sysconfig/network and set default gateway IP address: # vi /etc/sysconfig/network Sample outputs: ## setup default gateway ## GATEWAY=192.168.1.254 You can add additional static route for eth0 by editing /etc/sysconfig/network-scripts/route-eth0 file as follows: 192.168.12.0/24 via 192.168.1.56 dev eth0 The above config sets static routing for network 192.168.12.0/24 via 192.168.1.1 router. The address 192.168.1.1 is the IP address leading to the remote network. It is preferably the next hop address but the address of the exit interface will work. The “next hop” means the remote end of a link, for example a gateway or router. The dev option can be used to specify the exit interface interface but it is not required. Add as many static routes as required. Debian / Ubuntu Linux persistence static routing configuration Edit /etc/network/interfaces file, enter: # vi /etc/network/interfaces Append the following in eth0 section: up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254 down route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254 Save and close the file.