Static route in Linux

To add route in linux we can use the following command:

route add -net 10.50.140.0 netmask 255.255.255.0 gw 192.168.16.16 dev eth0

The above command will add a route in the routing table. We can check by the command:

route -n

The disadvantage of the command that as soon as the system reboots the route is removed you have to run the command again.To add route such that it stay even after the reboot we can edit one file and that will keep the route in the routing table even after the reboot.

Inside directory

/etc/network

there is a file named as interfaces we can add the following line into it:

post-up route add -net 10.1.1.0 netmask 255.255.255.0 gw 192.168.16.16

If you try adding the following line it might not work.

route add -net 10.1.1.0 netmask 255.255.255.0 gw 192.168.16.16

Above command have been tested in Kali Linux 1.0

Advertisements
This entry was posted in Linux. Bookmark the permalink.