MAC address (Media access control address) is a unique identifier assigned to the network interface controller (NIC), it will be used as a network address in the network segment, all hosts with a network card have a separate MAC address, the address contains a total of 48 bits, occupying A normal MAC address is represented in the format shown below, using two hexadecimal digits for each byte.
|
|
Because MAC addresses need to be unique, IEEE assigns address segments based on the manufacturer of the device. The first 24 bits of the 48-bit MAC address are the device manufacturer’s identifier, also known as Organizationally Unique Identifier (OUI), and the next 24 bits are the serial number; if each device manufacturer can guarantee that all MAC addresses in the same namespace are unique, then all MAC addresses in the world can be guaranteed to be unique.
MAC addresses can be represented using two different formats, the 48-bit EUI-48 and the 64-bit EUI-64. This article will use MAC addresses in EUI-48 format, and EUI-64 is mainly used for the IPv6 protocol, which we will not discuss in this article. In general, the MAC address will use 24 bits to represent the serial number of the organization, but because many organizations do not produce so many devices, in practice, three different sizes of address blocks are divided.
- MA-L (MAC Address Block Large) - contains a 24-bit organizational identifier and 24-bit address.
- MA-M (MAC Address Block Medium) - contains a 28-bit organization identifier and 20-bit address.
- MA-S (MAC Address Block Small) - contains a 36-bit organization identifier and 12-bit address.
These three different sizes of address blocks are also completely different prices, MA-L registration price of 2995 U.S. dollars, and MA-S registration price of 755 U.S. dollars, interested and needy readers can be in the IEEE official purchase, in the ideal case, all the addresses together worth about 52 trillion dollars ~ ~, really defined and mastered the standard can lie waiting for others to register to make money ~ ~.
This MAC address segment distributed by the agency and the device vendor to ensure that the address is unique is to ensure that the network address of all hardware worldwide, but in practice, the global uniqueness is not guaranteed and we do not need the address of the global uniqueness, mainly because of the following two reasons.
- we can modify the MAC address of the NIC directly through software on different operating systems.
- It is only necessary to ensure that the MAC addresses in a LAN are not duplicated for the network to work properly.
Modifying Addresses
Modifying the MAC address of a network device is very simple, both on Linux and on macOS. In the Linux operating system we can modify the MAC address on the device using the command ifconfig
.
As long as we use the above command, we can easily modify the MAC address of the current NIC, but it is recommended not to use it on a remote Linux machine, it is better to test the relevant command on the local Linux, and it is also better to use the command to change the MAC address back after the modification test is completed; you can also use the ifconfig command to modify the MAC address on macOS, which is almost identical to the way Linux is used.
Because the MAC address is bound to the hardware, this way of modifying the MAC address is actually temporary, once the operating system reboots, these changes will be undone by the system, and to make similar changes permanent, you need to execute the corresponding command or modify the corresponding NIC configuration file when the system reboots.
Local Area Network Communication
All computers and end devices need to be connected to a LAN through network adapters. Each adapter has a unique link layer address, also called a LAN address or MAC address, and MAC addresses are designed with a flat structure that they do not change with the network they are on.
When a device’s network adapter wants to send a data frame to another adapter, it inserts the MAC address of the destination adapter into an Ethernet frame as shown below. Each Ethernet frame is similar to an IP datagram, containing the source and destination addresses, except that the address in the Ethernet frame is the MAC address, while the address in the IP datagram is the IP address.
Data transmission in LAN is not routed and forwarded by IP address in network layer, however, IP address is generally the only information that the sending hosts know, and you still need to know their MAC addresses to send data in LAN. When our device wants to send data to other devices, it will first obtain the MAC address corresponding to the destination IP address in the LAN through ARP (Address Resolution Protocol): 1.
- the source host will send an ARP request to the current LAN, and the destination MAC address is
FF-FF-FF-FF-FF-FF
, which means the current request is a broadcast request, and all devices in the LAN will receive the request. - the hosts receiving the ARP request all check whether the destination IP and their own IP addresses are the same.
- if the IP addresses do not match, the host ignores the current ARP request.
- if the IP address is the same, the host sends an ARP response directly to the source host; 3.
- after receiving the ARP response, the source host updates the local cache table and continues to send data to the destination host.
In LAN, we usually use Hub or Switch to connect different network devices. Since all data frames are broadcasted to all hosts in the LAN connected by hub, using the same MAC address usually does not cause much problem; however, the switch will learn the MAC addresses of different devices in the LAN and forward the data frames to specific hosts, so if the LAN is composed of switch, it will affect the network communication.
Suppose two network devices A and B in the LAN with identical MAC addresses, namely 6e:77:0f:b8:8b:6b
, encounter the following situation when device A wants to send an Ethernet frame to device B: 1.
- device A sets both the source and destination addresses to
6e:77:0f:b8:8b:6b
in the constructed Ethernet frame and sends the data to the switch. - the switch receives the data frame from device A, learns the MAC address of device A from the source address of the data frame and inserts the record
6e:77:0f:b8:8b:6b -> A
into the local cache. - the switch discovers that the destination address of the received data frame will point to network device A, so it forwards the data back to A.
Because of the switch’s MAC address learning policy, we cannot use the same MAC address in the same LAN, but because MAC address is a concept in link-layer networks, network transmission across LANs needs to pass the network layer IP protocol, so there is no similar problem when using the same MAC address in different LANs.
Summary
MAC address is an important concept in link layer networks, where Ethernet data frames will be forwarded by MAC address in LANs, and globally unique MAC address is very ideal situation, however, in real network scenarios, we do not need to ensure such a strong restriction that.
- MAC addresses can be modified by software, and third-party cottage vendors will not apply for a separate MAC address segment in IEEE, and they may also steal MAC addresses applied by other vendors.
- Ensuring that MAC addresses are unique in a LAN will not cause network problems, and MAC addresses in different LANs can be the same.
The above conclusion is not to say that globally unique MAC addresses are meaningless; on the contrary, we should ensure that MAC addresses are as unique as possible so that we don’t need to manually confirm the MAC addresses of all devices when setting up LANs and reduce the workload of network engineers. In the end, let’s look at some more open related issues, interested readers can think carefully about the following questions.
- What is the relationship between MAC addresses and IP addresses?
- Why do we need an IP address when we have a MAC address?