Using the Linux route command
Posted by raxsoJun 21
What is a route
A route is a rule used by your kernel to determine how to get someplace on a network. IP routes (routes on an IP network) and other types of routable networks. Routes are stored in the Linux kernel are accessible for viewing and editing to users.
Checking the route table in Linux
netstat -rn
route
The table will look something like this.
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
127.0.0.0 127.0.0.1 255.0.0.0 UG 0 0 0 lo
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth1
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
Adding and Removing a specific host in Linux
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
This will add a temporary route that will clear after reboot.
To set the default gateway betwen reboots edit /etc/sysconfig/network with the following line
GATEWAY=192.168.0.1
Add a static route
route add -net 192.168.100.0 netmask 255.255.255.0 eth0
This will route all traffic toward this subnet to the eth0 interface
Manually add a static non gateway route
route add -net 10.8.100.0 netmask 255.255.255.0 gw 10.0.16.140
Note: The old gw will still remain and may need to be taken out for the system to function properly.
Routes are made permanent in Red Hat Linux by adding routes to /etc/sysconfig/static-routes Checking the route table in Windows NT
route print
Adding and Removing a network in Windows NT
route add 10.10.10.0 mask 255.255.255.0 192.168.0.1
route delete 10.10.10.0 mask 255.255.255.0 192.168.0.1
Adding and Removing a specific host in Windows NT
route add 10.10.10.45 192.168.0.1
route delete 10.10.10.45 192.168.0.1
Adding a Default GW in Windows NT
route add 0.0.0.0 mask 255.255.255.255 192.168.0.1
or
route add 0.0.0.0 192.168.0.1
or
route -p add 0.0.0.0 192.168.0.1
route delete 0.0.0.0
or
route delete 0.0.0.0 mask 255.255.255.255
or
route delete 0.0.0.0 mask 255.255.255.255 192.168.0.1
Routes are made permanent in Windows NT by using “-p” with the route add command. Here is an example:
route -p add 10.10.10.45 192.168.0.1
Like this blog? Why not buy me a cup of coffee?




![[hackers black book]](http://raxso.net/images/hbb-ani-misuse.gif)





Thanks! My brother found this very useful!
heids last blog post..Random Musings About Art And Life
[Reply]