route命令可以观察当前机器的路由表
一般使用route -n命令,否则显示出来的不是ip地址而是主机名
[root@gw sysconfig]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
21.21.21.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
21.21.21.0 21.21.21.2 255.255.255.0 UG 0 0 0 tun0
121.49.110.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
20.30.2.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 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
192.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 121.49.110.1 0.0.0.0 UG 0 0 0 eth1
上面是实验室网关的路由表,其中第一列(Destination)和第三列(Genmask)共同决定了一个网络报文的目的地,如果一个报文的目的地在上述两个值的网段内,那么就按照发送到第二列(Gateway)的目的地中去,如果这一列的值为0.0.0.0,那么就不用找网关了,直接就由本机发送到目的IP去。发送过程需要有ARP协议的帮忙。当然如果网段有重叠,那么靠前的规则会起作用。
附:
添加路由
route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.10.1
查看路由状态
route -n
删除路由
route del -net 192.168.20.0 netmask 255.255.255.0