In teaching computer network courses, I often encounter such a problem, why two addresses are needed: one is MAC (physical address) and the other is IP address. There are various explanations. Basically, one viewpoint is that one is a physical address and the other is a logical address. However, such an explanation is too abstract, what is physics, and what is logic. These abstract expressions make people unable to understand their essence. Let me talk about this issue below.

To illustrate this problem, you must first talk about what the goal of the computer network is. The fundamental goal of a computer network is to transfer data from one point to another. It sounds simple, but it contains a lot of meaning. For example, if the two points are connected on the same network or across the network, how can the data be correctly transmitted to the other party, what to do if there is an error, and so on.

To illustrate the nature of the problem, we first simplify the problem: assume that the two points are within a network. In this case, only the MAC address is required. For example, a plurality of computers are grouped into a network through a switch, and in order to find each other, they must be identified by an address. Just like sending a courier, if there is no address, the courier cannot send the courier to the location of the other party. This is what we call the MAC address. When point A wants to pass data to point B, the MAC address of B, the destination address, is added to the header of the data. Of course, the active address in the header, that is, the sender’s MAC address, there are other information, such as for verification and so on. This assembled data is called a frame. Then point A sends the frame out through the network card.

At this point, after receiving the frame, the switch looks up its own forwarding table. The forwarding table mainly has two columns, one column is a MAC address, and the other column is a port corresponding to the MAC address. There are only two cases of finding results: found or not found. If found, the data is forwarded from the port corresponding to the MAC. If not found, it is very simple, the switch will broadcast the frame to all ports (except the port that the frame enters), so there will definitely be a suitable port received. This method of broadcasting is rude and works very well.

This is the role of the MAC address. The MAC address is recorded on the physical device of the network card and is generally unchangeable.

However, if the two points are not in one network. Then you need an IP address. Because the IP address has two parts, one is the network address and the other is the host address. Therefore, through the IP address of the other party, it is possible to determine whether the other party and the device are in a network. If you are in a network, as mentioned above, you only need to know the MAC address of the other party to communicate.

If not in a network, the network layer of the machine considers that data should be sent to the gateway. The reason is obvious. If you are not in a network, you must first send the data out of the network. How to send out the network, of course, is sent to the gateway, because the gateway is equivalent to the network’s guard. In order to send data to the gateway, you also need to know the MAC address of the gateway. How do you know the MAC address of the gateway? This involves the ARP protocol.

There is an ARP table in the computer cache. The table has two main columns: one column is the IP address, and the other column is the MAC address. This table is not born, it is continuously learned as the network card receives various communication data in the network.

Having said that, if there is a MAC address corresponding to the gateway IP address in the ARP table, the problem is converted into data transmission within the network, which has been clearly explained above. If there is no MAC address corresponding to the gateway IP address in the ARP table, the ARP protocol is started, that is, broadcast to the network, and the MAC address of the IP address is inquired. The result of the broadcast inquiry is that after the gateway receives the broadcast, it finds that it is asking for its own MAC address, so it responds to the inquiry party’s own MAC address. Then the problem of sending data to the gateway is also translated into data transmission within the network. The above has been very clear.

Everyone found that there is no IP address required for inter-network communication. Because it is necessary to judge whether it is intra-network communication or off-net communication by IP address. Some might say that having a MAC address with a feature that distinguishes the network doesn’t require IP. In fact, this is not practical. Each NIC has a unique MAC address when it leaves the factory. It is impossible to know which network you are using when you play it, that is, it is inherently incapable of distinguishing the characteristics of the network. And it does not need to have this feature. Because the MAC is only responsible for device-to-device communication is enough. This layer of communication is true communication, so it is called physical communication.

When transmitting data across the network, you need to consider the path of the transmission, that is, in order to reach the destination, where the next hop should go, and then hop to the destination. Intra-network transmission does not need to consider the transmission path, as long as it is sent out, it can arrive. In the worst case, it can be reached by broadcast transmission. When transmitting across the network, this trick is not working. Therefore, inter-network transmission needs to consider the transmission between networks, and it is necessary to use an address that can represent the characteristics of the network, that is, an IP address. So the IP address is responsible for network to network transmission.

As for the gateway to the next step, the machine will not be able to manage it. This machine can only guarantee the transmission within the network, that is, the concept of next hop. The next hop can only be handled by the gateway. In fact, the gateway is an interface of the router. The gateway uses the IP address to determine the route, finds the routing table to determine which network the next hop should go to, and then sends the data out of the interface of the router that connects to that network. Sending out also determines whether the target IP is the same network as the current routing interface. The problem is back to the process described above. So go back and forth.

It can be seen that the concept of IP address and MAC address is not contradictory. There are different levels between them. Just like having a leader, there must be a mass of people, and no one can do without it. The data is passed from one point to another. It takes several networks, and the network route is what needs to be solved by using an IP address. Intranet transmission requires the use of a MAC address for transmission. It can be seen that there is no real communication transmission in the network, and how to realize communication between networks. And if there is no path for network routing, it is impossible for the data to reach the destination because there is no direction.

If you dig deeper, the concept of an address can also include a URL. Just like Google’s website, why do we need URL and IP? This is beyond the scope of this topic.