ARP protocol, take you to understand the ARP protocol

Table of contents

1. Overview of the ARP protocol

2. Four situations of using ARP

3. ARP cache

Fourth, the working principle of ARP

1. Address resolution

2. Address cache

5. ARP message format

1. ARP request message format

2. ARP response message format

6. Gratuitous ARP

7. Proxy ARP


1. Overview of the ARP protocol

 

Address Resolution Protocol (ARP) is a protocol for resolving IP addresses into physical addresses. In the TCP/IP protocol, the transmission of data packets needs to know the MAC address of the target host, while the IP address is only a logical address and cannot be directly used for the transmission of data packets. Therefore, it is necessary to use the ARP protocol to convert the IP address into a MAC address so that the data packet can be correctly transmitted to the target host.

The ARP protocol is a connectionless protocol, which can perform address resolution without establishing a connection. It is done between network layer and data link layer, so it can be used on different data link layers.

2. Four situations of using ARP

1. When a host sends data packets to other hosts in the local network, it needs to convert the IP address of the target host into a MAC address so that the data packets can be correctly transmitted to the target host.

2. When the host sends a data packet to the router in the local network, it needs to convert the IP address of the router into a MAC address so that the data packet can be correctly transmitted to the router.

3. When the router sends a data packet to a host in the local network, it needs to convert the IP address of the target host into a MAC address so that the data packet can be correctly transmitted to the target host.

4. When the router sends data packets to hosts in other networks, it needs to convert the IP address of the next-hop router into a MAC address, so that the data packets can be correctly transmitted to the next-hop router.

3. ARP cache

ARP cache refers to the mapping table of IP address and MAC address stored in the host or router. When a host or router needs to convert an IP address to a MAC address, it will first check whether the mapping relationship already exists in the ARP cache. If it exists, the address resolution is performed directly using the mapping relationship; if it does not exist, an ARP request packet needs to be sent for address resolution.

The mapping relationship in the ARP cache is time-limited, generally ranging from a few minutes to a few hours. When the mapping relationship expires, the host or router will resend the ARP request message for address resolution and update the mapping relationship in the ARP cache.

Fourth, the working principle of ARP

 

The working principle of the ARP protocol can be divided into two steps: address resolution and address caching.

1. Address resolution

When a host or router needs to convert an IP address to a MAC address, it will first check whether the mapping relationship already exists in the ARP cache. If it exists, the address resolution is performed directly using the mapping relationship; if it does not exist, an ARP request packet needs to be sent for address resolution.

The ARP request message contains the MAC address and IP address of the source host, and the IP address of the target host. When the target host receives the ARP request message, it will encapsulate its own MAC address and IP address in the ARP response message and return it to the source host. After receiving the ARP response message, the source host stores the MAC address and IP address of the target host in the ARP cache, and uses the mapping relationship for address resolution.

2. Address cache

After the host or router successfully performs address resolution, it will store the mapping relationship between the IP address and the MAC address in the ARP cache. When address resolution is required next time, the host or router will first check whether the mapping relationship already exists in the ARP cache. If it exists, the address resolution is performed directly using the mapping relationship; if it does not exist, the ARP request message needs to be resent for address resolution.

The mapping relationship in the ARP cache is time-limited, generally ranging from a few minutes to a few hours. When the mapping relationship expires, the host or router will resend the ARP request message for address resolution and update the mapping relationship in the ARP cache.

5. ARP message format

ARP packets are divided into ARP request packets and ARP response packets, and their formats are as follows:

1. ARP request message format

| 2 bytes | 2 bytes | 1 byte | 1 byte | 2 bytes | 6 bytes | 4 bytes | 6 bytes | 4 bytes |
|---------|---------|--------|--------|---------|---------|---------|---------|---------|
| Hardware Type | Protocol Type | HLEN | PLEN | Operation | Sender MAC Address | Sender IP Address | Target MAC Address | Target IP Address |

- Hardware Type: Indicates the hardware type, such as Ethernet, Token Ring, etc.
- Protocol Type: Indicates the protocol type, such as IP, IPX, etc.
- HLEN: Indicates the length of the hardware address, for example, the length of an Ethernet address is 6 bytes.
- PLEN: Indicates the length of the protocol address, for example, the length of an IP address is 4 bytes.
- Operation: Indicates the type of operation, such as 1 for ARP request and 2 for ARP response.
- Sender MAC Address: Indicates the MAC address of the sender.
- Sender IP Address: indicates the IP address of the sender.
- Target MAC Address: Indicates the MAC address of the target host. Since it is an ARP request message, this field is empty.
- Target IP Address: indicates the IP address of the target host.

2. ARP response message format

| 2 bytes | 2 bytes | 1 byte | 1 byte | 2 bytes | 6 bytes | 4 bytes | 6 bytes | 4 bytes |
|---------|---------|--------|--------|---------|---------|---------|---------|---------|
| Hardware Type | Protocol Type | HLEN | PLEN | Operation | Sender MAC Address | Sender IP Address | Target MAC Address | Target IP Address |

- Hardware Type: Indicates the hardware type, such as Ethernet, Token Ring, etc.
- Protocol Type: Indicates the protocol type, such as IP, IPX, etc.
- HLEN: Indicates the length of the hardware address, for example, the length of an Ethernet address is 6 bytes.
- PLEN: Indicates the length of the protocol address, for example, the length of an IP address is 4 bytes.
- Operation: Indicates the type of operation, such as 1 for ARP request and 2 for ARP response.
- Sender MAC Address: Indicates the MAC address of the sender.
- Sender IP Address: indicates the IP address of the sender.
- Target MAC Address: Indicates the MAC address of the target host.
- Target IP Address: indicates the IP address of the target host.

6. Gratuitous ARP

Gratuitous ARP means that when a host or router updates its own ARP cache, it sends an ARP response message to other hosts on the local network, so as to update the ARP cache of other hosts. The function of gratuitous ARP is to speed up the communication speed between hosts in the network and reduce the number of sending ARP request packets.

For example, when host A changes its own MAC address, it will send gratuitous ARP response packets to other hosts in the local network to update the ARP caches of other hosts. In this way, when other hosts send data packets to host A, they can directly use the new MAC address without sending an ARP request message for address resolution.

7. Proxy ARP

Proxy ARP means that when a router receives an ARP request packet, it sends an ARP response packet to other hosts on the local network, so as to perform address resolution instead of the target host. The role of proxy ARP is to solve the problem of subnet division existing in the network, so that hosts in different subnets can communicate.

For example, when host A sends a data packet to host B, if host A and host B are not in the same subnet, then host A needs to send the data packet to the router for forwarding. In this process, host A needs to convert the IP address of the target host into a MAC address, but it does not know the MAC address of host B. At this time, the router can use proxy ARP to send an ARP response packet to host A, so as to replace host B for address resolution. In this way, host A can correctly send the data packet to host B.

Guess you like

Origin blog.csdn.net/weixin_74021557/article/details/131233662