Why’s THE Design is a series of articles about programming decisions in THE field of computing. In each article, we present a specific question and discuss THE pros and cons of this Design and its impact on implementation from a different perspective. If you have a question you’d like to know more about, leave a comment below.

A Media Access Control address (MAC) is a unique identifier assigned to a Network Interface controller (NIC). It acts as a Network address in a Network segment. Each host with a network adapter has a separate MAC address, which contains 48 bits and takes up 6 bytes of space to represent 281,474,976,710,656 network devices. A normal MAC address is represented in the following format, with each byte using two hexadecimal digits:

6e:77:0f:b8:8b:6b
Copy the code

To ensure MAC addresses are Unique, IEEE allocates address segments based on the device manufacturer. The first 24 bits of a 48-bit MAC address are the Organizationally Unique Identifier (OUI) of the device manufacturer. The next 24 bits are the serial number; If every device manufacturer can ensure that all MAC addresses in the same namespace are unique, then all MAC addresses in the world can be guaranteed to be unique.

Figure 1 – MAC address

MAC addresses can be expressed in two different formats, namely 48-bit EUI-48 and 64-bit EUI-643. In this article, WE will use the MAC address format euI-48, which is mainly used for IPv6. We will not discuss it in this article. MAC addresses typically use 24 bits to represent the organization’s serial number. However, since many organizations do not produce such a large number of devices, there are three different address blocks in practice:

Figure 2-MA-L, MA-M, and MA-S

  • MA-L(MAC Address Block Large) – contains a 24-bit organization identifier and a 24-bit Address;
  • MAC Address Block Medium (MA-M) – Contains a 28-bit organization identifier and a 20-bit Address.
  • MAC Address Block Small (MA-S) – Contains a 36-bit organization identifier and a 12-bit Address.

The registration price of MA-L is $2995, while the registration price of MA-S is $755. Interested and interested readers can purchase 5 from IEEE’s official website. In an ideal world, the total value of all addresses is approximately $52 trillion. Sure enough, if you have defined and mastered the standard, you can lie back and wait for others to register to make money.

This method of distributing MAC segments by organizations and ensuring that the addresses are unique is to ensure that all hardware in the world has unique network addresses. However, in practice, global uniqueness is not guaranteed and we do not need global uniqueness for two reasons:

  • On different operating systems, we can change the MAC address of the network adapter directly by software.
  • You only need to ensure that the MAC addresses on a LAN do not duplicate, so that the network can work normally.

Modify the address

Whether on Linux or macOS, changing the MAC address of a network device is very simple. In Linux, you can run the ifconfig command to change the MAC address:

$ ifconfig eth0 | grep ether
        ether 6e:77:0f:b8:8b:6b  txqueuelen 1000  (Ethernet)
$ ifconfig eth0 down
$ ifconfig eth0 hw ether 6e:77:0f:b8:8b:6a
$ ifconfig eth0 up
$ ifconfig eth0 | grep ether
        ether 6e:77:0f:b8:8b:6a  txqueuelen 1000  (Ethernet)
Copy the code

As long as we use the above command, we can easily change the MAC address of the current network adapter. However, it is recommended not to use the command on the remote Linux machine, it is better to test the relevant command on the local Linux, after the modification test is completed, it is also better to use the command to change the MAC address back. You can also change MAC addresses on macOS using the ifconfig command in almost exactly the same way as on Linux.

The MAC address is bound to the hardware, so changing the MAC address is temporary. Once the operating system restarts, the MAC address will be revoked. To make the change permanent, you need to run the corresponding command or modify the corresponding NIC configuration file 6 during the system restart.

LAN communication

All computers and terminal devices are connected to the LAN through network adapters. Each adapter has a unique link layer address, also known as a LAN address or a MAC address. MAC addresses are designed in a flat structure that does not change from network to network.

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 the Ethernet frame shown below. Each Ethernet frame is similar to an IP datagram, containing both the source and destination addresses, except that the address in the Ethernet frame is a MAC address. The address in the IP datagram is the IP address:

Figure 3 – Ethernet frame

Data transmission on the LAN is not routed and forwarded through IP addresses at the network layer. However, IP addresses are generally the only information known by the data host. To send data on the LAN, you still need to know their MAC addresses. When a device wants to send data to another device, it obtains the MAC Address corresponding to the destination IP Address through ARP.

  1. The source host sends ARP requests to the current LAN. The destination MAC address isFF-FF-FF-FF-FF-FF, which indicates that the current request is a broadcast request and all devices on the LAN can receive the request.
  2. The host receiving the ARP request checks whether the destination IP address is the same as its own IP address.
    1. If the IP addresses are inconsistent, the host ignores the current ARP request.
    2. If the IP addresses are the same, the host sends an ARP response 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.

Figure 4 – Address resolution protocol

In lans, we usually use hubs or switches to connect different network devices. Since all data frames are broadcast to all hosts on a LAN connected to a hub, using the same MAC address generally does not cause too many problems. However, switches learn the MAC addresses of different devices on the LAN and forward data frames to specific hosts, so if the LAN is made up of switches, network communication can be affected.

Figure 5 – Hubs and switches

Suppose there are two network devices A and B with identical MAC addresses on the LAN, namely, 6E: 77:0F: B8:8B: 6B. When device A wants to send Ethernet frames to device B, the following situation occurs:

  1. Device A sets both the source address and destination address to6e:77:0f:b8:8b:6bAnd send data to the switch;
  2. After receiving A data frame from device A, the switch learns the MAC address of device A from the source address of the data frame and sends the MAC address of device A to the switch6e:77:0f:b8:8b:6b -> AThis record is inserted into the local cache;
  3. The switch finds that the destination address of the received data frame points to network device A, so it forwards the data back to DEVICE A.

Because of the MAC address learning strategy of the switch, we cannot use the same MAC address in the same LAN. However, because THE MAC address is a concept in the link layer network, the network transmission across the LAN needs to pass the IP protocol at the network layer. So using the same MAC address on different Lans does not have similar problems.

conclusion

MAC address is an important concept in link layer network. Ethernet data frames are forwarded by MAC address in LAN. It is ideal to have a globally unique MAC address, but in actual network scenarios, we do not need to guarantee such strong restrictions:

  • MAC addresses can be modified by software. However, third-party counterfeiters do not apply for an independent MAC address segment in IEEE and may steal MAC addresses applied by other vendors.
  • Unique MAC addresses on lans do not cause network problems. The MAC addresses on different Lans can be the same.

This is not to say that a globally unique MAC address is meaningless. On the contrary, we should ensure that the MAC address is as unique as possible, so that we do not need to manually confirm the MAC address of all devices when building a LAN, reducing the workload of network engineers. In the end, let’s take a look at some of the more open-ended questions that interested readers can ponder:

  • What is the relationship between MAC addresses and IP addresses?
  • Why do we need IP addresses when we have MAC addresses?

If you have questions about the content of this article or want to learn more about the reasons behind some design decisions in software engineering, you can leave a comment below on this blog. The author will respond to the questions in this article and select the appropriate topics for subsequent content.


  1. Wikipedia: Mac Address en.wikipedia.org/wiki/MAC_ad… ↩ ︎

  2. Organizationally Unique Identifier Vendor List standards-oui.ieee.org/oui.txt ↩︎

  3. Creating EUI – 64 -based Interface Identifiers tools.ietf.org/html/rfc237… ↩ ︎

  4. What is a MA-L, MA-M, MA-S assignment? Macaddress. IO/FAQ/what – is… ↩ ︎

  5. MAC Address Block Large (MA – L) standards.ieee.org/products-se… ↩ ︎

  6. How (and) according to Your MAC Address on Windows, Linux, and MAC www.howtogeek.com/192173/how-… ↩ ︎

Transfer application





Creative Commons Attribution 4.0 International License agreement

The article images

Guide to illustration of technical articles