Article directory
MAC address, IP address and ARP protocol
data link layer
The MAC address is the address used by the MAC sublayer of Ethernet
internet layer
- The IP address is the address used by the Internet layer of the TCP/IP architecture;
- The ARP protocol belongs to the Internet layer of the TCP/IP architecture, and its function is to know the IP address assigned to the device. Using the ARP protocol, the MAC address of the device can be obtained through the IP address;
Although the IP address and the ARP protocol belong to the Internet layer (not the data link layer) of the TCP/IP architecture, they have a certain relationship with the MAC address, and our daily network applications are inseparable from the MAC address, IP Address and ARP protocol. Therefore, we discuss these three together.
MAC address
Why is there a MAC address?
If the data link layer of the point-to-point channel does not need to use the address, the two parties can directly transmit data to each other; while the data link layer of the broadcast channel must use the address to distinguish each host
- When multiple hosts are connected to the same broadcast channel, in order to realize communication between two hosts, each host must have a unique identifier, that is, a data link layer address;
- The frame sent by each host must carry the addresses identifying the sending host and the receiving host. Since this type of address is used for media access control MAC (Media Access Control), this type of address is called a MAC address;
The MAC address is generally solidified in the EEPROM of the network card (network adapter), so the MAC address is also called the hardware address ;
This does not mean that MAC addresses belong to the physical layer in the network architecture!
In general, the user host will contain two network adapters: a wired LAN adapter (wired network card) and a wireless LAN adapter (wireless network card). Each network adapter has a globally unique MAC address. Switches and routers tend to have more network interfaces, so they will have more MAC addresses. To sum up, strictly speaking, a MAC address is a unique identifier for each interface on the network, rather than a unique identifier for each device on the network.
MAC address format
Byte sending order: first byte-sixth byte
Bit transmission order within a byte: b0-b7
Unicast and Broadcast
Unicast:
1 to 1 send
broadcast:
1 to many send
ip address
An IP address is an address used by hosts and routers on the Internet (Internet) to identify two pieces of information:
- Network number: identifies millions of networks on the Internet, the network number of N9 in the figure below is 192.168.1
- Host number: Identify different hosts (or router interfaces) on the same network, as shown in the figure below, the router address is 254, and the two hosts are 1 and 2
Application of ip address and mac address in network architecture:
Although it seems that the mac address and the ip address have the same function, there are obvious differences in the functions of both parties in the process of multi-routing forwarding
Changes of P address and MAC address during packet forwarding
The source IP address and destination IP address remain unchanged during packet forwarding;
The source MAC address and destination MAC address change link by link (or network by network) during packet forwarding.
ARP protocol
The role of the ARP protocol
Find out the corresponding MAC address based on the known ip address
ARP cache table
Each host has a table, which is used to store the corresponding relationship between the ip address and mac address of other hosts. When host B wants to find the mac address corresponding to 192.168.0.1, it can search according to this table. If you want to find in this table When there is no stored data, it is necessary to broadcast an ARP request message
ARP request message
When the ARP cache table of host B does not store the MAC address of host C and wants to know the MAC address of host C, host B will broadcast and send an ARP request message
ARP request message content
Host B writes its own ip address and mac address into the message and specifies the ip address of the mac address you want to query (the actual message format must be much more complicated, here is just a brief description of the content)
Since it is sent by broadcast, all hosts in the network where the host is located will receive the message, and compare the destination ip address of the message with its own ip address, and if they are the same, send a unicast frame Send the mac address and record the mac address and ip address of host B
Host B records the address of host C after receiving the unicast frame
Static vs Dynamic Type
Dynamic: automatically obtained, the default life cycle is two minutes;
Static: manually set, the life cycle is different under different operating systems, for example, it does not exist after the system is restarted or it is still valid after the system is restarted.
ARP usage range
It can only be used on the network with the same network number, and cannot be used across networks