Tuesday, September 13, 2011

route add command in linux

Sponsored Links
You can add a routing rule in a linux system as follows. It will work all linux systems including redhat, centos, ubuntu and debian

Syntax
route add -net network_id netmask subnet_mask gw gateway_ip dev device_name

root@cpaneltest [~]# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.10 dev eth0

Checking the rule
root@cpaneltest [~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.51    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.52    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.0     192.168.1.10    255.255.255.0   UG    0    0    0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

You can delete the above rule as follows
root@cpaneltest [~]# route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.10 dev eth0

Checking again
root@cpaneltest [~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.51    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.52    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
root@cpaneltest [~]#
Sponsored Links

No comments:

Post a Comment

Be nice. That's all.