

When a host IP packet sent to the destination is forwarded through multiple routers, the destination IP address remains unchanged.
When the ip packet is forwarded via routing, do the source ip and destination ip change?
This question is often asked in recent interviews with network professionals. The answer cannot be changed unless a nat conversion is performed. (Recommended learning: web front-end video tutorial)
But the mac address changes, because the sending end does not know the mac address of the destination host at first, so the mac address changes every time it passes through a router .
How to get the destination mac address?
TCP/IP uses the ARP protocol. For example, if a new intranet is created, if machine A is looking for machine B, when encapsulating FRAME (the data format used by the second layer of OSI), the other party's MAC must be encapsulated. At the beginning, A does not know B's MAC, but only knows the IP. It sends an ARP packet, the source IP is its own, the destination IP is B's, the source MAC is its own, and the destination MAC is broadcast.
Then the request packet is broadcast within the intranet. When other machines receive the packet, they compare the destination IP with their own IP. If not, they discard it. When B received it, he found that the IP was the same as his own, so he agreed to the request of the packet and sent his MAC to A. If B is a machine in another subnet, then the router will determine that B is in another subnet, and then the router will return its MAC to A. When A sends a packet to B in the future, the destination MAC will be encapsulated by the router.
Routing and forwarding process:
When the data flow sent from host A to host B is encapsulated into an IP data packet at the network layer, the header of the IP data packet contains the source address and destination address. Host A will use the 24-bit IP network mask 255.255.255.0 configured on this machine to perform an AND operation with the target address to determine whether the target network address and the network address of this machine are in the same network segment. If not forward the IP packet to the gateway.
Host A will also obtain the MAC address of the default gateway through an ARP request before sending it to the gateway. The IP data packet at the data link layer of host A is encapsulated into an Ethernet data frame and then sent to the gateway... which is a port on the router.
When the gateway router receives the Ethernet data frame and finds that the target MAC address in the data frame is the physical address of one of its own ports, the router will remove the encapsulation of the Ethernet data frame. The router thinks that this IP packet is to be forwarded through itself, and then it matches the routing table. After matching the routing entry, it sends the packet to the next address.
This is how the router forwards data packets, so it will never change the IP address. Only the MAC will be changed.
When a data packet is transmitted to the router, the router first compares its destination address with the routing table. If it is a local network, it will not be forwarded to the external network. Instead, it is forwarded directly to the destination host in the local network; but if the destination address is compared with the routing table and it is found that it is not in the local network, if there is NAT, the IP of the source address will be changed (the IP address of the original source address will be changed to the IP address of the router) ), the router forwards the data packet to the corresponding port for communication.
The above is the detailed content of When a host IP packet sent to the destination is forwarded through multiple routers, does the destination IP change?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
