As Linux users, we sometimes need to change the MAC address of our network adapters. This process is also called spoofing or faking a MAC address. This article explains how to change a MAC address through an Ubuntu 18.04 LTS system.

What is a MAC Address

MAC, that stands for Media Access Control, is a six byte ID permanently embedded in the firmware of a network adapter. This address can be read by an operating system and network where the adapter is installed. All network nodes such as workstations and printers etc. are identified by these MAC addresses over the network. These addresses are not identical, even for two similar device models of the same manufacturer. All MAC addresses need to follow the standards set by IEEE, the Institute of Electrical and Electronics Engineers.

Why change a MAC address?

So why do we need to change a MAC address? There are mainly the following two reasons to change it:

The most common reason to change a MAC address is to maintain privacy. If you are connected to a public network, the best way to keep your ID unexposed it to fake the MAC.

If a network administrator has blocked your MAC id on a firewall or router, you can spoof your id and be able to pass through it.

How to view current MAC address

In order to view the MAC addresses of all your network devices, you can use the following command on your Ubuntu terminal:

$ ip link show

Tip: You can open the Terminal through the Ctrl+Alt+T shortcut

The above output from my system shows MAC addresses of three network devices installed on my system. The part after “link/ether” is where you will see the MAC address of a particular device but we have blurred it for privacy reasons.

There is another way to view MAC addresses, but you may first need to install net-tools on your system through the following command:

$ sudo apt install net-tools

Then, run the following command:

$ ifconfig | grep ether

How to change MAC address

In order to change the MAC address of a device, you first need to install a command line utility called the macchanger.

Open the Terminal either through the Dash or the Ctrl+Alt+T shortcut and then run the following command:

$ sudo apt-get install macchanger

AdvertisementAdvertisement

During the installation process, you will encounter the following configuration message:

Select Yes through the arrow keys and then press Enter in order to configure macchanger to run automatically whenever a network device is brought up or down.

The following command will let you get the interface-name of a device that you will be using later to change its MAC address:

$ ip addr

The highlighted interface-name is the one we will be using in our following examples.

Setting up a Random MAC ID

The following command will assign a random, but viable, MAC id to your network adapter:

Sytnax:

$ macchanger -r <interface-name>

Example:

$ macchanger -r enp37s0

Setting up a Specific MAC ID

The following command will assign a specific MAC id to your network adapter:

Sytnax:

$ macchanger --mac=XX:XX:XX:XX:XX:XX <interface-name>

Restoring the MAC address to original

If you need to restore the MAC address of a device to its original state, you can use the following command:

Syntax:

$ macchanger -p <interface-name>

Example:

macchanger -p enp0s3

Through the simple steps described in this article, you can view and change your Mac addresses and also restore them to the original ones whenever needed.