网络相关配置笔记之route -n 的详细解释(linux)
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.190.90.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 0 0 0 eth1
192.168.0.0 10.77.238.254 255.255.0.0 UG 0 0 0 eth0
0.0.0.0 169.254.0.0 0.0.0.0 UG 0 0 0 eth1
前两条是自动生成的,因为是直连的网段,在每块网卡上每配置一个IP就会生成一条记录(一个网卡上可以配置多个IP)。表示去往这两个网段的数据包,直接由网卡接口eth0及eth1发送出去
这两条记录中的gateway并没有意义,Flags那一列中有G时才会使用Gateway。这两条路由并没有这样的标志,由于它们是本地的,匹配这些条目的数据包会直接通过Iface列中的网卡发送出去。
后两条表达的意思:
192.168.0.0 10.77.238.254 255.255.0.0 UG 0 0 0 eth0
表示去往192.168.0.0网段的数据包由网关10.77.238.254通过网卡eth0来转发
0.0.0.0 169.254.0.0 0.0.0.0 UG 0 0 0 eth1
表示去往所有目标地址数据包由网关169.254.0.0 通过网卡eth1来转发
其中,对于0.0.0.0的解释
If used in a routing table, it identifies the default gateway; a route to 0.0.0.0 is the default one, i.e. the one used when there is not any more specific route available to a destination address.
意思是0.0.0.0代表的是匹配所有目标地址,但注意默认网关的描述the one used when there is not any more specific route available to a destination address,一般路由匹配要符合掩码最长匹配原则,而默认路由的掩码是最短的,它只有在没有其他匹配条目的时候才会被选择。