The communication process across the network, the role of routing, and the default gateway

In the following network topology diagram, the network segment where switch 0 is located is 192.168.1.0/24, the network segment where switch 1 is located is 192.168.2.0/24, and each has 2 hosts:
insert image description here

Suppose PC0 (192.168.1.10/32) wants to communicate with PC4 (192.168.2.11/32), how to achieve it?

A router is needed in the middle. We know that the destination address of the data packet sent by PC0 is across the network segment, that is, it needs to go out of the gateway . The gateway is the exit of the network segment where the data packet originates. The gateway address is generally the first one or two addresses of the network segment where it is located, and the gateway is generally integrated in the router, called the next hop . The routing address of the first hop is also called the default gateway.

Each host in the subnet needs to configure the default gateway, that is, the next hop: the default gateway of PC0 is 192.168.1.1/32, and the default gateway of PC4 is 192.168.2.1/32. In this way, the data packet that PC0 wants to send to PC4 will first arrive at the network card with address 192.168.1.1/32 of the router, and the router will send it out from the network card at 192.168. In other words, routers are responsible for relaying data packets in the middle .

IP and MAC changes during communication between PC0 (192.168.1.10/32) and PC4 (192.168.2.11/32):

  • When PC0 sends a data packet to PC4, the data packet is first sent by PC0 to the router, and then sent by the router to PC4

    When the data packet is sent from PC0 to the router, the destination IP is the IP of PC4 (192.168.2.11/32), the destination MAC is the MAC of the 192.168.1.1/32 network card of the router, the source IP is the IP of PC0 (192.168.1.10/32), and the source MAC is the MAC of PC0

    When the data packet is sent from the router to PC4, the destination IP is the IP of PC4 (192.168.2.11/32), the destination MAC is the MAC address of PC4, the source IP is the IP of PC0 (192.168.1.10/32), and the source MAC is the MAC of the 192.168.2.1/32 network card of the router

  • When PC4 sends a data packet to PC0, the data packet is first sent by PC4 to the router, and then sent by the router to PC0

    When the data packet is sent from PC4 to the router, the destination IP is the IP of PC0 (192.168.1.10/32), the destination MAC is the MAC of the 192.168.2.1/32 network card of the router, the source IP is the IP of PC4 (192.168.2.11/32), and the source MAC is the MAC address of PC4

    When the data packet is sent to PC0 by the router, the destination IP is the IP of PC0 (192.168.1.10/32), the destination MAC is the MAC of PC0, the source IP is the IP of PC4 (192.168.2.11/32), and the source MAC is the MAC of the 192.168.1.1/32 network card of the router

It can be seen from the above that in the one-way communication process, the addresses of the source IP and the destination IP are unchanged, while the MAC address is constantly changing .

In the above topology diagram, PC0 still needs to send a data packet to PC4. When the data packet arrives at router 1, router 1 does not know the path to PC4, so it is necessary to add routing rules to the routing table on router 1, so that it knows that the data packet should be sent to the address of the 192.168.2.0/24 network segment, which router to go to, here is router 2. The same applies to other routers until reaching the destination host PC4.

The condition for a smooth network is that there is going and returning, so when the data packet returns from PC4 to PC0, all the routers along the way need the transfer path of the data packet, that is, the return route is configured so that it knows which router the address of the data packet sent to the 192.168.1.0/24 network segment needs to go to.

Artificially added routes are called static routes , but it is inconvenient to configure static routes when there are too many network segments connected to the router. You can let the router learn the next transit address of the data packet by itself, which is called dynamic routing .

Source code and other data acquisition methods

Friends who want to get source code and other tutorial materials, please like + comment + bookmark , triple!

After three times in a row , I will send you private messages one by one in the comment area~

 

Guess you like

Origin blog.csdn.net/GDYY3721/article/details/131768289