简体   繁体   English

了解路由表条目

[英]Understanding Routing table entry

I want to ask a question about route command in Linux. 我想问一个关于Linux中路由命令的问题。 I have enter following command in Linux terminal 我在Linux终端输入以下命令

> route

and got the output: 得到了输出:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
link-local      *               255.255.0.0     U     1000   0        0 eth0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

I don't understand it. 我不明白。 Does this mean that any packet with ip 192.168.1.0 will go out from * gateway? 这是否意味着任何带有ip 192.168.1.0数据包都将从*网关出去? Why is it DESTINATION written there shouldn't it be source because the packet going out from my host have source IP of 192.168.1.0 ? 为什么DESTINATION写在那里不应该是源,因为从我的主机发出的数据包的源IP为192.168.1.0

Can anyone explain me the meaning of this entry in terms of packet going out and coming to my host? 任何人都可以解释这个条目的意思,包括出去和来到我的主机?

Let's go through the lines one by one: 让我们一个接一个地看一遍:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     1      0        0 eth0

This says that any packet with a destination of 192.168.1.0 through 192.168.1.255 will be sent out eth0 without using a gateway (unless a more-specific route overrides this one). 这表示目的地为192.168.1.0到192.168.1.255的任何数据包都将在不使用网关的情况下发送出eth0 (除非更具体的路由覆盖此目的)。

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0

This says that any packet with a destination of 192.168.122.0 through 192.168.122.255 will be sent out virbr0 without using a gateway. 这表示目的地为192.168.122.0到192.168.122.255的任何数据包都将在不使用网关的情况下发送到virbr0 (Again, unless a more-specific route overrides this one.) (同样,除非更具体的路线覆盖此路线。)

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
link-local      *               255.255.0.0     U     1000   0        0 eth0

This says that any packet with a link-local address will be sent out interface eth0 with no gateway. 这表示任何具有链路本地地址的数据包都将从没有网关的接口eth0发送出去。

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

This says that any packet to a destination without another route will be sent out eth0 , using 192.168.1.1 as a gateway. 这表示使用192.168.1.1作为网关,将没有其他路由的任何数据包发送到eth0

  • Destination = the address of the network that the packet is headed to Destination =数据包前往的网络地址

The "default" means that if the destination is not found in any of the other rules than use this rule. “默认”表示如果在使用此规则之外的任何其他规则中找不到目的地。

  • Genmask = The subnet mask Genmask =子网掩码

If there is more than one address in the routing table that works for the outgoing packet, the rule with the higher subnet mask will be used. 如果路由表中有多个地址适用于传出数据包,则将使用具有较高子网掩码的规则。 If those are tied, then metric comes into play but that will be different based on what protocol is being used. 如果这些是绑定的,那么度量标准就会发挥作用,但根据使用的协议,它会有所不同。

  • Interface = On-board connection 接口=板载连接

For example, the laptop I am on currently has three interfaces: 例如,我目前使用的笔记本电脑有三个接口:

  1. Ethernet card 以太网卡
  2. Wireless card 无线网卡
  3. Bluetooth 蓝牙

Routers generally have at least 2 interfaces for each side, 1 for each network they are a part of. 路由器通常每侧至少有2个接口,每个网络都有1个接口。 For most home routers, 1 interface is part of your home network and the other is part of the external network headed toward your ISP. 对于大多数家用路由器,1个接口是家庭网络的一部分,另一个接口是前往ISP的外部网络的一部分。

  • Gateway = Next hop 网关=下一跳

This is where the packet will be sent if the destination is not on the same network as the sender. 如果目标与发送方不在同一网络上,则会在此处发送数据包。

If the value is in "*" or "On-link" or the address of the current device... these all mean the same thing. 如果值是“*”或“On-link”或当前设备的地址......这些都意味着相同的事情。 It means that the packet is addressed to a device that is directly reachable by the current host. 这意味着数据包将寻址到当前主机可直接访问的设备。 In other words, they're on the same network so the gateway won't actually be used because the host will know the data link layer (MAC) address of the destination and be able to send it directly there. 换句话说,它们位于同一网络上,因此实际上不会使用网关,因为主机将知道目的地的数据链路层(MAC)地址并能够直接在那里发送。 These values are just used for human readability in this case. 在这种情况下,这些值仅用于人类可读性。

As for the process of sending a packet: 至于发送数据包的过程:

  • Destination and Genmask are used to figure out which rules are a match for the destination address of the outgoing packet. 目标和Genmask用于确定哪些规则与传出数据包的目标地址匹配。
  • Interface is used to decide what communication device on the machine to send it through. 接口用于决定机器上的通信设备发送它。
  • Gateway is the address of the device on the same network that it will send the packet to (through). 网关是将数据包发送到(通过)的同一网络上的设备的地址。

192.168.1.0(-255) is the local destination, once it reaches its local destination (most likely 192.168.1.1, your router) it will be rerouted to the external IP destination. 192.168.1.0(-255)是本地目的地,一旦到达其本地目的地(很可能是192.168.1.1,您的路由器),它将被重新路由到外部IP目的地。 This shows how your computer chooses to send its packets which is relatively simple because most if not all of the packets leaving your computer travel to your router before they are sent to their destination. 这显示了您的计算机如何选择发送相对简单的数据包,因为大多数(如果不是全部)离开计算机的数据包在发送到目的地之前都会前往路由器。

A much more interesting routing table would be that of your router which would deal with many of both external and internal destinations. 一个更有趣的路由表将是您的路由器,它将处理许多外部和内部目的地。 If you investigate this you will be able to learn a lot more about routing. 如果你研究这个,你将能够学到更多关于路由的知识。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM