大网数据广告活动
服务器运维问答

How does an IP packet know which gateway to take?

· 52CE 我爱测

Suppose two gateways exist on the same network. If I understand correctly, the IP routing table on sender's computer decides which packets get routed through which gateway. IP routing tables contain the IP address of the gateway.…

问题原文

原帖链接 · Simon Farshid · CC BY-SA 3.0

Suppose two gateways exist on the same network. If I understand correctly, the IP routing table on sender's computer decides which packets get routed through which gateway.

IP routing tables contain the IP address of the gateway.

How is this IP address of the gateway used when sending IP packets?

已采纳解答

原帖链接 · kubanczyk · CC BY-SA 4.0

TL;DR: the gateway's address is only stored in an Ethernet frame that holds that TCP/IP packet

The server->switch->router traffic, as well as server->switch->server traffic, is where IP addressing doesn't actually play any meaningful part. It's the world of underlying protocol, most likely Ethernet. So it's a world that runs on MAC addressing.

So you only need to resolve the confusion that a default gateway is an IP address. Well, it is, kind-of... what is shown to human... but that gateway's IP is only needed to do one thing, that is to ask: who has 192.168.1.1 around here? The answer comes saying the gateway is MAC 88:99:aa:bb:cc:dd:ee:ff. (That's ARP query/response, the translator between the two worlds.) The MAC is what is actually used. Packet goes to that MAC on Ethernet level, despite the fact that on IP level the packet specifies a completely unrelated destination IP address of a final receiver.

So the packet is marked to go to a chosen gateway by setting the "destination MAC" field of the Ethernet frame. The field determines which gateway on that network will get it, if there are multiple gateways. (The "frame" is an underlying capsule that holds the packet or part of the packet.)

Generalization: while route tables are the core of IP, their column named Next Hop is never implemented with IP addressing when the packet travels the wire. The Next Hop always actually uses Ethernet, MPLS, or other underlying protocol:

$ ip route show
 192.168.98.0/24     via 192.168.99.1 dev eth0
|                   |                         |
|  <- IP world ->   | <- underlying world  -> |
|                   |                         |

Above, even when the underlying world mentions something like 192.168.99.1, which is an IP-world concept, they don't actually mean literally that.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。