Route command gives the possibility to specify static routes.
The syntax of the command is Unix flavour spific:
These methods of changing the route table don't last accross reboots. Listed below are methods to make any of these changes permanent.
Checking the route table in Linux
netstat -rn
route -r
Adding and Removing a Network in Linux
route add -net 10.10.10.0/24 gw 192.168.0.1
route del -net 10.10.10.0/24 gw 192.168.0.1
or
route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.253
route del -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.253
Adding and Removing a specific host is Linux-flavour specific:
route add -host 10.10.10.45 gw 192.168.0.1
route del -host 10.10.10.45 gw 192.168.0.1
Adding a Default GW in Linux
route add default gw 192.168.0.1
route del default gw 192.168.0.1
Note: The old gw will still remain and may need to be taken out for the system to function properly.
The routing information above is not persistent across reboots. After a reboot, the routing information will be lost and you need to add them in again.
To make the routing information persistent, add the “route add” line as seen above into the /etc/rc.local file.
Sample /etc/rc.local file.
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.253
Making addition permanent
Routes are made permanent in Red Hat Linux by adding routes to /etc/sysconfig/static-routes
In Suse: Yast -> Network Devices -> Network card -> Edit -> Routing
Or edit /etc/sysconfig/network/routes if you prefer the CLI.
Soure:
http://thedaneshproject.com/posts/how-to-add-route-in-linux/
http://www.softpanorama.org/Net/Netutils/route_in_linux.shtml
thanks!!!
Penyon
ReplyDelete