How to Change the MAC of an Ethernet and WiFi Network Card in Linux

All network cards, regardless of whether they are Ethernet (wired) or WiFi (wireless) have a 48-bit identifier at the link layer level, the MAC address. The MAC address is a set of hexadecimal numbers (6 blocks of two hexadecimal characters) usually separated by a colon. This MAC address is essential for the proper functioning of the local network, since the MAC is used by the ARP protocol to find the different computers on the network, and it is also used in IPv6 networks to configure the SLAAC using EUI- 64. Today in this article we are going to explain how to change the MAC address on your network card on Linux systems, ideal for doing it on servers.

The MAC address is recorded on the network card (NIC), either Ethernet or WiFi. In principle, this MAC cannot be modified because it is a unique identifier of the device in question, there cannot be two MAC addresses in the same segment of the network, because that would lead to many problems. The MAC addresses of a certain device (network card, router, switch, access point, IP camera with WiFi) are unique worldwide, since they are written directly, in binary form, in the hardware at the time of manufacture. Also, in the 48-bit MAC address, the first 24 bits identify the manufacturer of the device, and the last 24 bits identify the device in question.

change the MAC of an Ethernet

The MAC address of a card cannot be easily modified permanently, however, in modern operating systems it can be modified at the software level. Users of Linux-based operating systems, for example Debian, can easily change the MAC address of our network card from a terminal using different methods. Next, we are going to show you how to change the MAC address of our Linux server with the main methods.

Change MAC address on Linux servers with ip link

The iproute2 suite is the one that is currently used to manage the entire network of a server or Linux operating system, we can change the IP address, routing, create new secondary routing tables, and we can also change the MAC address of a certain network card very easily and quickly.

The only thing we will have to do is show the current MAC with the following command:

ip link show interfaz

In our case, the interface is “ens33”. Next, we have to disable the network card, if we do not disable it, the change of MAC will not work because it is in use.

ip link set dev interfaz down

We change the MAC address with the following command:

ip link set dev interfaz address XX:XX:XX:XX:XX:XX

And we lift the Ethernet network card:

ip link set dev interfaz up

In the following screenshot you can see the whole process:

This is the easiest and fastest way to change the MAC address, without the need to install anything at all.

Change MAC address with ifconfig

The ifconfig command has been used for many years to manage the network in Linux operating systems, but nowadays it is no longer used, in case you are still using it, we are also going to help you change the MAC address with this suite command.

The first thing to do is check the current MAC of our network card. To do this, we will open a terminal or a TTY in our system and type:

ifconfig

Once we know the current MAC address of our card, we must make the following configurations:

Disable the network card to which we are going to change the MAC address:

ifconfig eth0 down

We change the MAC of said card for the one we want (changing 00: 00: 00: 00: 00: 00 for the MAC in question that we want to establish).

ifconfig eth0 hw ether 00:00:00:00:00:00

We raise the network card again:

ifconfig eth0 up

As you have seen, changing the MAC address is really easy and fast with ifconfig, the same number of commands as with ip link. We must remember that ifconfig is no longer installed in the latest versions of Debian and other distributions, in favor of iproute2.

macchanger: automate MAC address change

The macchanger program is designed to automate the MAC address change, and even allows us to generate a completely random MAC address. This program is not installed by default, we have to install it ourselves through the repository:

sudo apt install macchanger

When installing it, it will ask us if we want it to run automatically when activating a network device, to have a new MAC address every time a network cable is connected or the WiFi network is activated, ideal to always have a different MAC.

To change the MAC address completely randomly on a certain interface, we must do the following:

macchanger -r interfaz

The program itself will inform us of the current MAC address, the permanent MAC (the one that is recorded on the card) and the new MAC address:

If we check the MAC with ip link show, we will see:

We also have the possibility that the MAC is random, but keeping the first 24 bits (manufacturer):

macchanger -e interfaz

Of course, we can put the MAC address that we want in the following way:

macchanger --mac=XX:XX:XX:XX:XX:XX interfaz

Finally, we can put the original MAC of the card:

macchanger -p interfaz

If we execute «–help» we can see the help provided by this program:

We hope that with these three ways that we have taught you, you can change the MAC address of your Ethernet or WiFi card easily and quickly.