Learn to use
"route" by example
All the experiments are done on this networking
infrastructure.
1. A single command "route" without any parameter
display the routing tables.
original routing tables:
[root@dublin /root]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
132.177.8.0 * 255.255.255.128 U 0 0 0 eth0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default phub0.cs.unh.ed 0.0.0.0 UG 0 0 0 eth0
[root@prague /root]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
132.177.8.0 * 255.255.255.128 U 0 0 0 eth0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default phub0.cs.unh.ed 0.0.0.0 UG 0 0 0 eth0
[root@madrid /root]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
132.177.8.0 * 255.255.255.128 U 0 0 0 eth0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default phub0.cs.unh.ed 0.0.0.0 UG 0 0 0 eth0
2. Add a static route to the routing table.
On prague add a route to network 192.168.2.0/24. It's accessible from eth1
[root@prague /root]# route add -net 192.168.2.0/24 dev eth1
or
[root@prague /root]# route add -net 192.168.2.0 netmask 255.255.255.0 dev
eth1
[root@prague /root]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
132.177.8.0 * 255.255.255.128 U 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U
0 0 0 eth1
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default phub0.cs.unh.ed 0.0.0.0 UG 0 0 0 eth0
Actually, this kind of route is added automatically when you bring up eth1.
3. Add a static route to a host
On prague, add a route to itself 192.168.2.2. "192.168.2.2 is at Ethernet
interface one"
[root@prague /root]# route add -host 192.168.2.2 dev eth1
[root@prague /root]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.2 * 255.255.255.255 UH 0 0 0 eth1
132.177.8.0 * 255.255.255.128 U 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth1
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default phub0.cs.unh.ed 0.0.0.0 UG 0 0 0 eth0
4. Add a route to reach a network to which this
host is not directly attached.
we need to know the gateway, and the gateways
need to on the network to which our host directly attached.
prague is not directly attached to network 192.168.1.0/24. Add a route:
#route add -net 192.168.1.0/24 gw 192.168.2.1 dev eth1
or
#route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth1
Now wee can access network 192.168.1.0/24 without any problem.
Note: We need to configure dublin as router. we need to turn on ip_forwarding
5. add a default route
#route add default gw phub0.cs.unh.edu dev eth0
Note: The following ip addresses won't use default route. They need
static route
10.0.0.0 - 10.255.255.255 (10/8 prefix)
172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
6. Delete a routing entry in routing table is
easy:
#route del -net 192.168.2.0/24
or
#route del -net 192.168.2.0 netmask 255.255.255.0