日期:2014-05-16  浏览次数:20607 次

linux route命令学习

route命令用于显示和操作IP路由表。

没有增加路由之前,route命令的结果如下,
sh-# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
sh-#

用户可以使用route add/del来增加或删除一条路由。
由于我的系统中有程序能够自动识别到插入网线的动作,所以程序会自动增加一条路由,
这样就不需要用户自动手动配置了。
sh-# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

default         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
sh-#

使用-c选项,用来显示路由缓存。
路有缓存用于某个目的地址在路由表中查找到匹配路由项后,就把目的地址对应的路由项缓存起来,
其目的是提高路由查找的效率。
sh-# route -C
Kernel IP routing cache
Source          Destination     Gateway         Flags Metric Ref    Use Iface
192.168.0.162   192.168.0.155   192.168.0.155         0      0        0 eth0
192.168.0.162   192.168.0.1     192.168.0.1           0      0       25 eth0
localhost.local localhost.local localhost.local l     0      0        4 lo
192.168.0.150   192.168.0.162   192.168.0.162   il    0      0       21 lo
192.168.0.1     239.255.255.250 239.255.255.250 ml    0      0      161 lo
192.168.0.162   static-reverse. 192.168.0.1           0      0        0 eth0
192.168.0.162   time-a.timefreq 192.168.0.1           0      0        0 eth0
192.168.0.155   192.168.0.162   192.168.0.162   il    0      0        5 lo
192.168.0.162   static-reverse. 192.168.0.1           0      0        0 eth0
192.168.0.162   192.168.0.150   192.168.0.150         0      0       33 eth0
192.168.0.155   255.255.255.255 255.255.255.255 ibl   0      0        0 lo
192.168.0.1     192.168.0.162   192.168.0.162   il &