Adding a route in Linux

is

If you can to access a network outside your local host’s network, and the same is not know to your default gateway, you will require to add static routes in your systems. Same will be required in scenarios when your host is connected to two networks and would like to reach a third network via a specific network.

 

The command to add a route in a Linux host to reach 192.168.100.x network via the NIC eth0 that has IP 92.168.10.1 is as follows:

# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.10.1 dev eth0

The above is a temporary setting that will stop working after the network restarts. To permanently add it you will have to create a file “/etc/sysconfig/network-scripts/route-eth0” and will need to add the following lines in the file.

ADDRESS0=192.168.100.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.10.1
Once saved, restart the network service.