Computer Network (6)-ARP is really simple

When using the IP protocol to send network packets, in addition to knowing the IP address of the destination host, it also needs to know its MAC address to complete the data encapsulation at the data link layer. In the network layer protocol, the IP protocol is in the middle position, and the ARP protocol in its lower left corner provides the IP protocol with the service of querying the MAC address.

1. How ARP works

1. Request the MAC address of the host in this network segment (such as 1 -> 2/3)

When the source host sends a message to the destination host, it will first look for the MAC address corresponding to the IP address of the destination host in its own ARP cache table.

If so, use it directly to complete the data link layer encapsulation.

If not, send an ARP broadcast request packet in this network segment. The packet includes the source host IP, MAC address, and destination host IP address.

All hosts in this network segment will receive this packet. If they find that their IP address is equal to the destination host's IP address in the ARP request packet, they will return an ARP unicast response packet to the source host, telling the source host its MAC address.

After the source host receives the response packet, it knows the MAC address it needs

The above process can be understood in a life-like way: the teacher is looking for LBW classmates and shouting in the class: Where is LBW? All the students heard the teacher's call, but only LBW would respond: Teacher, I am in the second column of the third row. You may not know. . .

2. Request the MAC address of the external network host (such as 1–>4/5)

When the source host sends a message to the destination host, the ARP request packet via this network segment has no response.

Then the source host will send the ARP request message to the default gateway (that is, the router port connected to the external network), after obtaining the gateway MAC address, encapsulate it into the destination MAC address of the data link layer, and send the IP message.

The IP packet arrives in the router, and it is found that the destination IP address is not the router, so the MAC address is changed to the MAC address of the next router and forwarded.

Suppose that after one or more times of forwarding between routers, the IP packet now arrives at the router where the destination host is located. The router first uses the APR protocol once, with the same principle as 1. Find the MAC address of the destination host, and then encapsulate it into an IP datagram , And sent to the destination host, so that a data transmission is completed.

2. ARP practice

1. View the local ARP cache table

Knock in CMD

arp -a

Command, you can view the ARP cache table of the machine. The cache table will store known IP addresses and their corresponding MAC addresses

2. Modify the ARP cache table (Windows XP)

Knock in CMD

arp -s IP address MAC address

Command, you can modify the ARP cache table, and the corresponding IP address and MAC address mapping will be modified. And because the MAC address is manually specified, the entry type will become static.

Guess you like

Origin blog.csdn.net/weixin_44580146/article/details/106897658