linux命令查看路由器 linux查看路由( 二 )


Flags:总共有多个旗标,代表的意义如下:
o U (route is up):该路由是启动的;
o H (target is a host):目标是一部主机 (IP) 而非网域;
o G (use gateway):需要透过外部的主机 (gateway) 来转递封包;
o R (reinstate route for dynamic routing):使用动态路由时 , 恢复路由资讯的旗标;
o D (dynamically installed by daemon or redirect):已经由服务或转 port 功能设定为动态路由
o M (modified from routing daemon or redirect):路由已经被修改了;
o !(reject route):这个路由将不会被接受(用来抵挡不安全的网域!)
o A (installed by addrconf)
o C (cache entry)
Metric 距离、跳数 。暂无用 。
The 'distance' to the target (usually counted inhops).Itis
notusedbyrecent kernels, but may be needed by routing dae-
mons.
Ref不用管,恒为0 。
Number of references to this route. (Not used in the Linuxker-nel.)
【linux命令查看路由器 linux查看路由】Use该路由被使用的次数,可以粗略估计通向指定网络地址的网络流量 。
Countof lookups for the route.Depending on the use of -F and
-C this will be either route cache misses (-F) or hits (-C).
Iface 接口,即eth0,eth0等网络接口名
Interface to which packets for this route will be sent.
范例一
单纯的观察路由状态
[root@linux ~]# route -n
Kernel IP routing table
DestinationGatewayGenmaskFlags Metric RefUse Iface
192.168.10.00.0.0.0255.255.255.0U000 eth0
169.254.0.00.0.0.0255.255.0.0U000 eth0
0.0.0.0192.168.10.300.0.0.0UG000 eth0
[root@linux ~]# route
Kernel IP routing table
DestinationGatewayGenmaskFlags Metric RefUse Iface
192.168.10.0*255.255.255.0U000 eth0
169.254.0.0*255.255.0.0U000 eth0
defaultserver.cluster0.0.0.0UG000 eth0
此外,观察一下上面的路由排列顺序喔,依序是由小网域(192.168.10.0/24 是 Class C),逐渐到大网域(169.254.0.0/16 Class B) 最后则是预设路由 (0.0.0.0/0.0.0.0) 。然后当我们要判断某个网路封包应该如何传送的时候,该封包会经由这个路由的过程来判断喔!举例来说,我上头仅有三个路由,若我有一个传往 192.168.10.20 的封包要传递,那首先会找 192.168.10.0/24 这个网域的路由,找到了!所以直接由 eth0 传送出去;如果是传送到 Yahoo 的主机呢? Yahoo 的主机 IP 是 202.43.195.52,我通过判断
1)不是 192.168.10.0/24,
2)不是 169.254.0.0/16 结果到达
3)0/0时 , OK!传出去了 , 透过eth0将封包传给192.168.10.30那部gateway主机?。∷运担酚墒怯兴承虻?。因此当linux命令查看路由器你重复设定多个同样的路由时,例如在你的主机上的两张网路卡设定为相同网域的IP时,会出现什么情况?会出现如下的情况:
KernelIProutingtable
DestinationGatewayGenmaskFlagsMetricRefUseIface
192.168.10.00.0.0.0255.255.255.0U000eth0
192.168.10.00.0.0.0255.255.255.0U000eth1
也就是说,由于路由是依照顺序来排列与传送的,所以不论封包是由那个介面(eth0, eth1)所接收,都会由上述的eth0传送出去,所以,在一部主机上面设定两个相同网域的IP本身没有什么意义!有点多此一举就是了 。除非是类似虚拟主机(Xen, VMware等软体)所架设的多主机时,才会有这个必要~
范例二
[root@linux ~]# route del -net 169.254.0.0 netmask 255.255.0.0 dev eth0
# 上面这个动作可以删除掉 169.254.0.0/16 这个网域!
# 请注意,在删除的时候,需要将路由表上面出现的资讯都写入
# 包括netmask , dev 等等参数喔!注意注意
[root@linux ~]# route add -net 192.168.100.0 netmask 255.255.255.0 dev eth0
# 透过 route add 来增加一个路由!请注意,这个路由必须要能够与你互通 。

推荐阅读