Host-to-host packet delivery consists of an interesting series of processes. In this multipart example, you will discover what happens "behind the scenes" when an IPv4 host communicates with another IPv4 host, firstly when a router is used. Secondly, when a switch is responsible for the host-to-host packet delivery process.
主機對主機的封包遞送包含一連串有趣的程序。在這個多段式範例中,你將探索當一個 IPv4 主機與另一個 IPv4 主機通訊時「幕後」發生了什麼事:首先是透過路由器的情況,接著是由交換器負責主機對主機封包遞送程序的情況。
Host-To-Host Packet Delivery (Step 1 of 14)
主機對主機的封包遞送(第 1 步,共 14 步)
In this example, the host 192.168.3.1 needs to send arbitrary application data to the host 192.168.4.2, located on another subnet. The application does not need a reliable connection, so it uses UDP. Because it is unnecessary to set up a session, the application can start sending data, using the UDP port numbers to establish the session and deliver the segment to the right application.
在這個範例中,主機 192.168.3.1 需要將任意應用程式資料傳送給位於另一個子網路上的主機 192.168.4.2。該應用程式不需要可靠連線,因此使用 UDP。由於不需要建立會議,應用程式可以直接開始傳送資料,並使用 UDP 連接埠號來建立會議並將區段遞送給正確的應用程式。
Host-To-Host Packet Delivery (Step 2 of 14)
主機對主機的封包遞送(第 2 步,共 14 步)
UDP prepends a UDP header (UDP HDR) and passes the segment to the IPv4 layer (Layer 3) with an instruction to send the segment to 192.168.4.2. IPv4 encapsulates the segment in a Layer 3 packet, setting the source address (SRC IP) of the packet to 192.168.3.1, while the destination address (DST IP) is set to 192.168.4.2.
UDP 會在前面加上一個 UDP 標頭(UDP HDR),並將區段傳遞給 IPv4 層(第 3 層),並指示將區段傳送到 192.168.4.2。IPv4 會將區段封裝成第 3 層封包,將封包的來源位址(SRC IP)設為 192.168.3.1,目的位址(DST IP)則設為 192.168.4.2。
Host-To-Host Packet Delivery (Step 3 of 14)
主機對主機的封包遞送(第 3 步,共 14 步)
When Host A analyzes the destination address, it finds that the destination address is on a different network. The host forwards any packet that is not destined for the local IPv4 network in a frame addressed to the default gateway. The default gateway is the address of the local router, which must be configured on hosts (PCs, servers, and so on). IPv4 passes the Layer 3 packet to Layer 2 with instructions to forward it to the default gateway. Host A must place the packet in its "parking lot" (on hold) until it has the MAC address of the default gateway.
當主機 A 分析目的位址時,發現目的位址位於不同的網路上。主機會將任何非本地 IPv4 網路的封包,以定址給預設閘道的框架轉送出去。預設閘道是本地路由器的位址,必須在主機(PC、伺服器等)上設定。IPv4 會將第 3 層封包傳遞給第 2 層,並指示將其轉送給預設閘道。在取得預設閘道的 MAC 位址之前,主機 A 必須先將封包放在其「暫存區」(保留)中。
Host-to-Host Packet Delivery (Step 4 of 14)
主機對主機的封包遞送(第 4 步,共 14 步)
To deliver the packet, the host needs the Layer 2 information of the next-hop device. The ARP table in the host does not have an entry and must resolve the Layer 2 address (MAC address) of the default gateway. The default gateway is the next hop for the packet. The packet waits while the host resolves the Layer 2 information.
為了遞送封包,主機需要下一跳裝置的第 2 層資訊。主機的 ARP 表中沒有相關項目,因此必須解析預設閘道的第 2 層位址(MAC 位址)。預設閘道是此封包的下一跳。在主機解析出第 2 層資訊之前,封包會先等待。
Host-To-Host Packet Delivery (Step 5 of 14)
主機對主機的封包遞送(第 5 步,共 14 步)
Because the host does not know the default gateway’s Layer 2 address, the host uses the standard ARP process to obtain the mapping. The host sends a broadcast ARP request looking for the MAC address of its default gateway.
由於主機不知道預設閘道的第 2 層位址,主機會使用標準的 ARP 程序來取得對應關係。主機會送出一個廣播 ARP 請求,以尋找其預設閘道的 MAC 位址。
Host-To-Host Packet Delivery (Step 6 of 14)
主機對主機的封包遞送(第 6 步,共 14 步)
The host has previously been configured with 192.168.3.2 as the default gateway. The host 192.168.3.1 sends out the ARP request, and the router receives it. The ARP request contains information about Host A. Notice that the first thing the router does is add this information to its own ARP table.
此主機先前已設定 192.168.3.2 作為預設閘道。主機 192.168.3.1 送出 ARP 請求,路由器收到後,該 ARP 請求中包含主機 A 的資訊。請注意,路由器要做的第一件事,就是將此資訊加入自己的 ARP 表。
Host-To-Host Packet Delivery (Step 7 of 14)
主機對主機的封包遞送(第 7 步,共 14 步)
The router processes the ARP request like any other host would and sends the ARP reply with its own information directly to the host's MAC address.
路由器會像任何其他主機一樣處理該 ARP 請求,並直接以自己的資訊送出 ARP 回覆給該主機的 MAC 位址。
Host-to-Host Packet Delivery (Step 8 of 14)
主機對主機的封包遞送(第 8 步,共 14 步)
The host receives an ARP reply to its ARP request and enters the information in its local ARP table.
主機收到針對其 ARP 請求的 ARP 回覆,並將該資訊記錄到自己的本地 ARP 表中。
Host-To-Host Packet Delivery (Step 9 of 14)
主機對主機的封包遞送(第 9 步,共 14 步)
Now, the Layer 2 frame with the application data can be sent to the default gateway. The pending frame is sent with the local host IPv4 address and MAC address as the source. However, the destination IPv4 address is that of the remote host, but the destination MAC address is the default gateway.
現在,帶有應用程式資料的第 2 層框架便可以送往預設閘道。這個待傳送的框架會以本地主機的 IPv4 位址與 MAC 位址作為來源。不過,目的 IPv4 位址是遠端主機的位址,而目的 MAC 位址則是預設閘道的位址。
Host-To-Host Packet Delivery (Step 10 of 14)
主機對主機的封包遞送(第 10 步,共 14 步)
When the router receives the frame, it recognizes its MAC address and processes the frame. At Layer 3, the router sees that the destination IPv4 address is not its address. A host Layer 3 device would discard the frame. However, because this device is a router, it passes all IPv4 packets that are not for the router itself to the routing process. The routing process determines where to send the packet.
當路由器收到該框架時,會辨識出這是自己的 MAC 位址並加以處理。在第 3 層,路由器發現目的 IPv4 位址並非自己的位址。若是第 3 層的主機裝置,會將此框架丟棄。然而,由於這個裝置是路由器,它會將所有非目的地為路由器本身的 IPv4 封包交由路由程序處理。路由程序會決定該將封包傳送到哪裡。
Host-To-Host Packet Delivery (Step 11 of 14)
主機對主機的封包遞送(第 11 步,共 14 步)
The routing process checks for the longest prefix match of the destination IPv4 address in its routing table. In this example, the destination network is directly connected. Therefore, the routing process can pass the packet directly to Layer 2 for the appropriate interface.
路由程序會在其路由表中查詢目的 IPv4 位址的最長前綴比對。在此範例中,目的網路是直接連接的,因此路由程序可以直接將封包傳遞給對應介面的第 2 層。
Host-To-Host Packet Delivery (Step 12 of 14)
主機對主機的封包遞送(第 12 步,共 14 步)
Assuming that the router does not have the mapping to 192.168.4.2, Layer 2 uses the ARP process to obtain the mapping for the IPv4 address and the MAC address. The router asks for the Layer 2 information in the same way as the hosts. An ARP request for the destination MAC address is sent to the link.
假設路由器沒有 192.168.4.2 的對應關係,第 2 層會使用 ARP 程序來取得該 IPv4 位址與 MAC 位址的對應關係。路由器會以和主機相同的方式查詢第 2 層資訊,並在鏈路上送出一個尋找目的 MAC 位址的 ARP 請求。
The destination host receives and processes the ARP request.
目的主機收到並處理該 ARP 請求。
Host-To-Host Packet Delivery (Step 13 of 14)
主機對主機的封包遞送(第 13 步,共 14 步)
The destination host receives the frame that contains the ARP request and passes the request to the ARP process. The ARP process takes the information about the router from the ARP request and places the information in its local ARP table. The ARP process generates the ARP reply and sends it back to the router.
目的主機收到包含該 ARP 請求的框架,並將此請求交給 ARP 程序處理。ARP 程序會從 ARP 請求中取得有關路由器的資訊,並將此資訊記錄到自己的本地 ARP 表中,接著產生 ARP 回覆並回傳給路由器。
The router receives the ARP reply, populates its local ARP table, and starts the packet-forwarding process.
路由器收到 ARP 回覆後,會填入其本地 ARP 表,並開始進行封包轉送程序。
Host-To-Host Packet Delivery (Step 14 of 14)
主機對主機的封包遞送(第 14 步,共 14 步)
The frame is forwarded to the destination. Note that the router changes Layer 2 address in frames as needed, but it will not change the Layer 3 address in packets.
此框架會被轉送給目的地。請注意,路由器會視需要變更框架中的第 2 層位址,但不會變更封包中的第 3 層位址。
Role of a Switch in Packet Delivery (Step 1 of 4)
交換器在封包遞送中的角色(第 1 步,共 4 步)
Typically, your network will have switches between hosts and routers. In this multipart example, you will see what happens on a switch when a host communicates with a router.
通常,你的網路中在主機與路由器之間會有交換器。在這個多段式範例中,你將看到當主機與路由器通訊時,交換器上發生了什麼事。
Remember that a switch does not change the frame in any way. When a switch receives the frame, it forwards it out of the proper port according to the MAC address table.
請記住,交換器不會以任何方式變更框架。當交換器收到框架時,會依照 MAC 位址表,將其從正確的連接埠轉送出去。
An application on host A wishes to send data to a remote network. Before an IP packet can be forwarded to the default gateway, its MAC address must be obtained. ARP on Host A creates an ARP request and sends it out as a broadcast frame. Before the ARP request reaches other devices on a network, the switch receives it.
主機 A 上的一個應用程式想要將資料傳送到遠端網路。在 IP 封包能被轉送給預設閘道之前,必須先取得其 MAC 位址。主機 A 上的 ARP 會建立一個 ARP 請求,並以廣播框架的形式送出。在 ARP 請求到達網路上的其他裝置之前,交換器會先收到它。
When the switch receives the frame, it needs to forward it out on the proper port. However, in this example, the source MAC address is not in the MAC address table of the switch. The switch can learn the port mapping for the source host from the source MAC address in the frame, so the switch adds the information to the table (0800:0222:2222 = port FastEthernet0/1).
當交換器收到此框架時,需要將其從正確的連接埠轉送出去。然而,在此範例中,來源 MAC 位址並不在交換器的 MAC 位址表中。交換器可以從框架中的來源 MAC 位址,學習到來源主機的連接埠對應關係,因此會將此資訊加入表中(0800:0222:2222 = FastEthernet0/1 連接埠)。
Role of a Switch in Packet Delivery (Step 2 of 4)
交換器在封包遞送中的角色(第 2 步,共 4 步)
Because the destination address of the frame is a broadcast, the switch has to flood the frame out to all the ports, except the one it came in.
由於此框架的目的位址是廣播位址,交換器必須將此框架洪泛(flood)到除了送入連接埠以外的所有連接埠。
Role of a Switch in Packet Delivery (Step 3 of 4)
交換器在封包遞送中的角色(第 3 步,共 4 步)
The router replies to the ARP request and sends an ARP reply packet back to the sender as a unicast frame.
路由器回覆此 ARP 請求,並以單播框架的形式將 ARP 回覆封包送回給發送端。
The switch learns the port mapping for the router’s MAC address from the source MAC address in the frame. The switch adds it to the MAC address table (0800:0333:2222 = port FastEthernet0/3)
交換器會從框架中的來源 MAC 位址,學習到路由器 MAC 位址的連接埠對應關係,並將其加入 MAC 位址表(0800:0333:2222 = FastEthernet0/3 連接埠)
Role of a Switch in Packet Delivery (Step 4 of 4)
交換器在封包遞送中的角色(第 4 步,共 4 步)
The destination address of the frame (Host A) is found in the MAC address table so that the switch can forward the frame out on port FastEthernet0/1. If the destination address were not found in the MAC address table, the switch would need to flood out the frame on all ports, except the one it came in.
由於此框架的目的位址(主機 A)已存在於 MAC 位址表中,交換器可以將此框架從 FastEthernet0/1 連接埠轉送出去。如果在 MAC 位址表中找不到目的位址,交換器就必須將此框架洪泛到除了送入連接埠以外的所有連接埠。
All frames pass through the switch unchanged. The switch builds its MAC address table based on the source address of received frames, and it sends all unicast frames directly to the destination host based on the destination MAC address and port that are stored in the MAC address table.
所有框架通過交換器時都不會被變更。交換器會根據收到框架的來源位址建立其 MAC 位址表,並依據 MAC 位址表中儲存的目的 MAC 位址與連接埠,將所有單播框架直接送往目的主機。

















