问题原文
原帖链接 · 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
