本文发表在 rolia.net 枫下论坛It's because router maintains a routing table (basically IP address<->MAC address and other informations).
An IP packet always contains the destination and source IP addresses(32bits). When a packet is transfered across the network, only the MAC address in layer 1 frame is changed hop by hop.
In a LAN, usually your computer stores the map between IP address and MAC adress, so you can directly add destination MAC address into ethernet frame, and puts the frame on the bus. If you find the IP address is not in the same sub-net as yours, you send the IP packet to the proxy/router with proxy/router's MAC address to let them forward the IP packet. When proxy/router check the IP address in the IP packet, they also ckeck their routing table to see if they can send the IP packet directly to the destination computer which is connected with the router. Otherwise, they forward the IP packet to the next better router according to the routing table and routing protocols. Then again and again until the packet arrives the destination.更多精彩文章及讨论,请光临枫下论坛 rolia.net
An IP packet always contains the destination and source IP addresses(32bits). When a packet is transfered across the network, only the MAC address in layer 1 frame is changed hop by hop.
In a LAN, usually your computer stores the map between IP address and MAC adress, so you can directly add destination MAC address into ethernet frame, and puts the frame on the bus. If you find the IP address is not in the same sub-net as yours, you send the IP packet to the proxy/router with proxy/router's MAC address to let them forward the IP packet. When proxy/router check the IP address in the IP packet, they also ckeck their routing table to see if they can send the IP packet directly to the destination computer which is connected with the router. Otherwise, they forward the IP packet to the next better router according to the routing table and routing protocols. Then again and again until the packet arrives the destination.更多精彩文章及讨论,请光临枫下论坛 rolia.net