SoFunction
Updated on 2025-04-12

Resolve IP address and MAC address

1. IP address

I believe everyone is familiar with IP addresses, which refer to the 32-bit address assigned to the host using the TCP/IP protocol. An IP address consists of four 8 octets separated by dots. For example, 192.168.0.1 is an IP address. This writing method is called dot-decimal format. An IP address consists of two parts: a network address and a host address. The number of bits assigned to these two parts varies depending on the address class (Class A, Class B, Class C, etc.). The network address is used for routing, while the host address is used to find a separate host within the network or subnet. An IP address makes it possible to route data from the source address to the destination address.

2. MAC address

As for MAC addresses, since we do not contact them directly, we may not be very familiar with them. In the OSI (Open System Interconnection) layer 7 network protocol (physical layer, data link layer, network layer, transmission layer, session layer, presentation layer, application layer) reference model, the second layer is the data link layer (Data Link). It contains two sublayers, the previous layer is logical link control (LLC: Logical Link Control), and the next layer is the MAC (Media Access Control) layer we mentioned earlier, that is, the media access control layer. The so-called media refers to the various physical environments through which signals are transmitted. Commonly used network media include cables (such as twisted pair, coaxial cable, optical fiber), as well as microwaves, lasers, infrared, etc., and sometimes the medium is also called physical media. The MAC address is also called a physical address, hardware address or link address, and is written inside the hardware when produced by the network equipment manufacturer. This address has nothing to do with the network, that is, no matter where the hardware (such as network cards, hubs, routers, etc.) with this address is connected to the network, it has the same MAC address. The MAC address cannot be changed and cannot be set by the user themselves.

3. The length, representation method, allocation method and its uniqueness of the MAC address

The length of the MAC address is 48 bits (6 bytes), usually represented as 12 hexadecimal numbers, separated by colons for each 2 hexadecimal numbers, such as: 08:00:20:0A:8C:6D is a MAC address, where the first 6 hexadecimal numbers 08:00:20 represents the number of the network hardware manufacturer, which is assigned by IEEE (Istitute of Electrical and Electronics Engineers, Association of Electrical and Electronics Engineers), and the next 3 hexadecimal numbers 0A:8C:6D represent the series number of a network product (such as a network card) manufactured by the manufacturer. Each network manufacturer must ensure that each Ethernet device it manufactures has the same first three bytes and a different last three bytes. This ensures that every Ethernet device in the world has a unique MAC address.

4. The role of IP addresses and MAC addresses in the Internet

Since each Ethernet device has a unique MAC address when leaving the factory, why do you still need to assign an IP address to each host? Or why is each host assigned a unique IP address? Why do you need to embed a unique MAC address during production of network devices (such as network cards, hubs, routers, etc.)? The main reasons are as follows: (1) The allocation of IP addresses is based on the topology of the network, not based on who created the network settings. This solution is not feasible if efficient routing solutions are based on the equipment manufacturer rather than the topological position where the network is located. (2) When there is an additional layer of address addressing, the device is easier to move and repair. For example, if an Ethernet card is broken, it can be replaced without obtaining a new IP address. If an IP host moves from one network to another, you can give it a new IP address without changing to a new network card. (3) Communication between computers in a local area network or a wide area network is ultimately manifested as sending data packets from the initial node on a certain form of link, from one node to another, and finally sending them to the destination node. The movement of data packets between these nodes is done by ARP (Address Resolution Protocol) responsible for mapping IP addresses to MAC addresses. Let’s use an example to see how IP address and MAC address combine to transmit data packets.

Suppose on the network, a data packet (named PAC) is sent from a host in Beijing (name A, IP address is IP_A, MAC address is MAC_A) to a host in Washington (name B, IP address is IP_B, MAC address is MAC_B). These two hosts cannot be directly connected, so when the packet is delivered, the data packet must pass through many intermediate nodes (such as routers, servers, etc.). We assume that during the transmission process, we have to pass through three nodes C1, C2, and C3 (the MAC addresses are M1, M2, and M3 respectively). Before sending the PAC, A sends an ARP request to find the MAC address M1 of the first intermediate node C1 that it must go through to reach IP_B, and then encapsulates these addresses in its packet: IP_A, IP_B, MAC_A and M1. After the PAC is transmitted to C1, the ARP will find the MAC address M2 of the second intermediate node C2 to be experienced according to its destination IP address IP_B, and then transmit the data packet with M2 to C2. And so on, until the address MAC_B of the host B with the IP address IP_B is finally found, and it is finally transmitted to the host B. During the transmission process, IP_A, IP_B and MAC_A remain unchanged, while the MAC address of the intermediate node is constantly changing through ARP (M1, M2, M3) until the destination address MAC_B.

5. Summary

Based on the above, we can summarize that the similarities between IP addresses and MAC addresses are both unique, and the main characteristics are:

1. For a device on the network, such as a computer or a router, its IP address is variable (but must be unique) and the MAC address is immutable. We can assign any IP address to a host as needed. For example, we can assign an IP address to a computer on the LAN to 192.168.0.112, or change it to 192.168.0.200. Once any network device (such as network cards or routers) is produced, its MAC address will never be unique and cannot be changed by the user.

2. Different lengths. The IP address is 32 bits and the MAC address is 48 bits.

3. Different allocation basis. The allocation of IP addresses is based on network topology, and the allocation of MAC addresses is based on manufacturers.

4. The addressing protocol layer is different. IP addresses are applied to the third layer of OSI, namely the network layer, while MAC addresses are applied to the second layer of OSI, namely the data link layer. The data link layer protocol can enable data to be passed from one node to another node of the same link (through the MAC address), while the network layer protocol can enable data to be delivered from one network to another (ARP finds the MAC address of the intermediate node according to the destination IP address, and transmits it through the intermediate node, thereby finally reaching the destination network).

Article entry: dnbm     Editor: dnbm