linux对于$route -n命令查看路由表的困惑?

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.55.1    0.0.0.0         UG    600    0        0 wlp3s0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlp3s0
192.168.55.0    0.0.0.0         255.255.255.0   U     600    0        0 wlp3s0

对于0.0.0.0有一点不了解。这是查到的对于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.

问题一:Destination中这个0.0.0.0代表的是啥?是匹配所有的目标ip吗,如果这样的话,后面两条记录不就失去意义了吗?

问题二:第二条和第三条记录Gateway中0.0.0.0表示的default gateway又是哪一个网关?而第一条记录查处的Gateway 192.168.55.1这个网关地址就是家里的路由器吗?

阅读 4.4k
1 个回答

问题一:0.0.0.0代表的是匹配所有目标地址,但注意默认网关的描述the one used when there is not any more specific route available to a destination address,一般路由匹配要符合掩码最长匹配原则,而默认路由的掩码是最短的,它只有在没有其他匹配条目的时候才会被选择。
问题二:这两条记录中的gateway并没有意义,Flags那一列中有G时才会使用Gateway。这两条路由并没有这样的标志,由于它们是本地的,匹配这些条目的数据包会直接通过Iface列中的网卡发送出去。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题