How to Change MAC Address in Linux

The MAC address is a unique identifier assigned to every device connected to a network. Even though the MAC address is permanent, you may want to change it on your device in some cases. For example, you can change the MAC address on your device to hide your identity or to resolve network compatibility issues. With that in mind, this guide will show you how to change the MAC address on a Linux device. So whether you’re a beginner or an experienced Linux user, follow this guide to modify the MAC address in a quick and easy manner.

Changing the MAC Address in Linux (2023)

Changing the MAC Address in Linux (2023)

What is MAC Address?

As mentioned above, the MAC Address (or Media Access Control address) is a unique identifier used to recognize devices connected to a network. This address is used to identify and communicate with other devices, be it a computer, smartphone, or printer, on a network.

The MAC address is a 48-bit hexadecimal addressconsisting ofsix sets of two digits or charactersseparated by colons or hyphens. It is also referred to as the Physical address or Burned-in address. That’s because the MAC address is assigned by the manufacturer and is burned into the device’s hardware. So it usually cannot be changed, or at least they don’t change on their own like an IP address.

Difference Between MAC Address and IP Address

Each network device needs at least two addresses to get recognized by other devices and network interfaces – one is the MAC address, and the other is the IP address (Internet Protocol address). While the former is used to uniquely identify devices on a network, the latter helps identify a device’s connection to the network. That means an IP address makes it easier to locate your device, so the network knows where to send your data. Moreover, the IP address gets assigned by theInternet Service Provider(ISP), and the MAC address is assigned by the manufacturer, as we mentioned above.

However, we can change the MAC address using some neat software tricks, which we will learn in this article. Unlike an IP Address, which can be changed permanently, theMAC address gets reverted to the originalmanufacturer’s address when you reboot the device.

Why You May Want to Change the MAC Address?

There may be numerous reasons why you want to change the MAC address on your Linux computer. Changing the MAC address makes the network devices treat you like a new individual. This canmake you completely anonymouson a public network, hence, protecting you from cyberattacks on a public network. You can also get access tounlimited free public Wi-Fiat airports, cafes, etc., by changing your device’s MAC address.

The MAC address change can also be used for some illegal activities, such as impersonating the admin of an organization. By changing your MAC address to that of the admin, you can gain illegal access to restricted networks. However, we condemn any such malicious actions and advise against them.

Installing Package to Change MAC Address in Linux

There are several Terminal tools, such as macchanger, net-tools, etc., that can help you change the MAC address on your Linux PC. Here, we have listed theLinux commandsto install both packages, so follow along.

To install macchanger and net-tools packages on a Debian-based system, use the following command:

sudo apt install macchanger net-tools

For CentOS-based systems, use the following command to install the packages:

sudo yum install macchanger net-tools

To install the two packages in Arch-based systems, use the following command:

sudo pacman -S macchanger net-tools

While installing the macchanger package, it displays a prompt asking users whether they wish to change the MAC address every time they boot into the system or not. Use the arrow keys to navigate the choices. Choose either Yes or No, depending on your preference. Then, hit Enter to confirm your choice.

How to Change the MAC Address Temporarily

Before you change the MAC address, you need to knowwhat is the name of the device and its current MAC address. To list all the network devices present on your system, use this command:

ifconfig

For older systems or in case of any errors, use the following command:

ip addr show

When you run the command, the first part of the output displays the Loopback address information, which can be recognized with thelolabel and is used for diagnosing any problems in the network.

The second part shows details about the network interface, which iseth0in this example. Furthermore, theethersub-label specifies the hardware address or the MAC address, which is08:00:27:05:10:68in our case. Theinetsub-label specifies the IPv4 IP address and theinet6sub-label specifies the IPv6 IP address.

Now that you have noted your network interface name, you first have to disable the device’s connection to the network to change its MAC address in Linux. Disable the device using the following command:

sudo ifconfig <interface_name> down

When you run this command, you will getdisconnected from the internet. If the above command does not work on your system, you can either reinstall the net-tools package or use the following command:

sudo ip link set dev <interface_name> down

After you have disabled the device’s network connection, you can now change the MAC address. Use the following command to change the MAC address in Linux.

sudo ifconfig <interface_name> down hw ether <new_mac_address>

Then, you can enable the device again using this command. Run the commands in order for the desired result.

sudo ifconfig <interface_name> up

In case of any errors, use the following command to change the MAC address and enable the device’s network connection:

ip link set dev <interface_name> address <new_mac_address>

ip link set dev <interface_name>up

To verify that the MAC address of your Linux system has changed successfully, run the following command:

ifconfig

And in case of any errors or if your system is old, use the following command:

ip addr show

How to Change the MAC Address Permanently

Like the previous section, you first need to list all the network devices in the system and note down the interface name using the following command:

ifconfig

To see the current MAC address of the network interface, use the following command:

sudo macchanger –show <interface_name>

When using the macchanger tool to change the MAC address permanently, you do not need to disable the device network connection and re-enable it. You can directly assign a random MAC address to your PC using the following command:

sudo macchanger -r <interface_name>

To assign a particular MAC address in Linux use the command below. You will need tospecify the MAC address(6 sets of two digits or characters separated by colons) you wish to assign to your Linux system. Here is what the syntax looks like:

sudo macchanger –mac=<mac_address> <interface_name>

For example, we have changed the mac address to00:00:00:31:33:73for the interfaceeth0using the command below.

sudo macchanger –mac=00:00:00:31:33:73 eth0

  1. To get a new MAC address each time you boot into the system, you can create a/etc/systemd/system/changemac@.servicesystemd unit file using a Linux text editor of your choice. For that, type the following command in the Terminal:

sudo vim /etc/systemd/system/changemac@.service

  1. Then, paste the following text inside the changemac@.service file:

In the above piece of code, a new MAC address is assigned to the network interface every time you boot your Linux computer. You can add a specific MAC address using the-moption instead of-rin the 10th line, as shown below:

ExecStart=/usr/bin/macchanger -m XX:XX:XX:XX:XX:XX %I

  1. Next, all you need to do is enable the service you just created using the following command:

sudo systemctl enable changemac@<interface_name>.service

Now, you are all set. Your Linux computer will automatically change the MAC address (permanently) to a new one every time you boot into a new session.

Frequently Asked Questions

Are MAC addresses permanent?

Yes, MAC Addresses are permanent and get assigned by the manufacturer of the network device. But they can be changed using some tricks in the Linux terminal, as shown above.

Do MAC addresses get reused?

Since the number of available MAC addresses is limited, manufacturers do need to reuse the MAC addresses.

How long is a MAC address?

A MAC address includes 48 bits or 6 bytes, where each byte consists of 2 hexadecimal digits. They are shown in sets of two, separated by a colon or hyphen.

Modify the MAC Address in Linux

Modify the MAC Address in Linux

Changing the MAC address in Linux is simple and can help improve your privacy and security while using the Internet. While you need to use the Terminal to modify the MAC address permanently, note that the steps might vary slightly depending on yourLinux distro. Further, while changing the MAC address on your Linux PC, make sure it does not conflict with any other MAC address, or else both addresses will get disconnected from the network. We hope this article helped you permanently change your MAC address on your Linux PC. If you have any questions, let us know in the comments below.

Beebom Staff

Bringing the latest in technology, gaming, and entertainment is our superhero team of staff writers. They have a keen eye for latest stories, happenings, and even memes for tech enthusiasts.

Add new comment

Name

Email ID

Δ

01

02

03

04

05