Adding a route in Linux


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 is as follows:

# route add -net netmask gw 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.

Once saved, restart the network service.