Home FAQ How To Change MAC address In Linux

How To Change MAC address In Linux

By sk
Published: Last Updated on 32.2K views

You may not want to expose the real MAC address when you are connected with a public WiFi hotspot. In such situations, you can simply change it or fake it with another MAC address. Some times, the network administrator might have blocked a particular MAC address in the router or firewall. In such cases, you can use this method to change the MAC id. Changing MAC address is also called spoofing MAC address or faking MAC address. In this brief tutorial, we will see how to change MAC address in Linux.

I tested this guide on CentOS 7 and Ubuntu 18.04 LTS server editions. It worked well as described below. Let us get started.

Find MAC address in Linux

First, let us find out the MAC address or Hardware address of a Network interface card in Linux.

$ ifconfig | grep HWaddr

Sample output:

enp0s3    Link encap:Ethernet  HWaddr 08:xx:xx:xx:xx:x1


$ ip link show
enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
 link/ether 08:xx:xx:xx:xx:x1 brd ff:ff:ff:ff:ff:ff


$ ifconfig | grep ether

Sample output:

ether 24:xx:xx:xx:xx:x9 txqueuelen 1000 (Ethernet)
ether c0:xx:xx:xx:xx:xf txqueuelen 1000 (Ethernet)

You can use any one of the above commands to find out the MAC id of a network interface card. These commands should work on almost all Linux distributions.

Now let us see how to change the MAC address.

Change MAC address in Linux

We can do this in two methods. Please be mindful that you should not do this on a live network card which is currently in use. If you do it, probably, your network connection will be terminated. Try this method with an additional card.

Method 1: Using Macchanger

Macchanger is simple utility to view, modify, and manipulate MAC addresses for your Network interface cards. It is available in almost all GNU/Linux operating systems.

On Arch Linux:

To install Macchanger in Arch Linux and its derivatives, run:

$ sudo pacman -S macchanger

On Fedora, CentOS, RHEL:

$ sudo yum install macchanger


$ sudo dnf install macchanger

On Debian / Ubuntu:

To macchanger in Debian, Ubuntu and its derivatives, run:

$ sudo apt-get install macchanger

Specify whether macchanger should be set up to run automatically every time a network device is brought up or down. This gives a new MAC address whenever you attach an ethernet cable or reenable wifi.

I recommend you not to run it automatically, unless you really need to change the MAC id every time. So, choose No and hit ENTER key to continue.

Change mac address 1

Macchanger has been installed.

Macchanger usage

To assign any random MAC address, run:

$ macchanger -r <interface-name>

To find out the network interface name, run:

$ ip addr

Sample output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 inet scope host lo
 valid_lft forever preferred_lft forever
 inet6 ::1/128 scope host 
 valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether 08:xx:xx:xx:xx:x1 brd ff:ff:ff:ff:ff:ff
 inet brd scope global enp0s3
 valid_lft forever preferred_lft forever
 inet6 fe80::a00:27ff:fe12:f8c1/64 scope link 
 valid_lft forever preferred_lft forever

Change mac address 2

As you see in the above screenshot, enp0s3 is my network interface card's name.

To change the MAC address of enp0s3 network card, run:

$ sudo macchanger -r enp0s3

After changing the MAC id, verify it using command:

$ ip addr

Sample output:

Change mac address 3

You will now see that MAC has been spoofed.

To change the MAC address to a specific value, specify any custom MAC address using command:

$ macchanger --mac=XX:XX:XX:XX:XX:XX 

Where XX:XX:XX:XX:XX:XX is the new MAC id that you wish to change to.

Finally, to return the MAC address to its original, permanent hardware value, run the following command:

$ macchanger -p enp0s3

Change mac address 4

However, you don't have to do this. Once you reboot the system, the changes will be automatically lost, and the actual MAC address will be restored again.

For more details, check the man pages:

$ man macchanger

Method 2: Using iproute2

First, turn off the Network card using command:

$ sudo ip link set dev enp0s3 down

Next, set the new MAC is using command:

$ sudo ip link set dev enp0s3 address XX:XX:XX:XX:XX:XX

Finally, turn it on back with command:

$ sudo ip link set dev enp0s3 up

Now, verify new MAC id using command:

$ ip link show enp0s3

Sample output:

link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff

Alternatively, you can do this using 'ifconfig' command as described below.

$ sudo ifconfig eth0 down
$ sudo ifconfig eth0 hw ether 00:80:48:BA:d1:30
$ sudo ifconfig eth0 up
$ ifconfig eth0 | grep HWaddr

That's it.

Suggested read:

As you can see, both methods are pretty easy. Choose any one that works for you. To revert back to the original MAC address, simply reboot your system.

Hope this helps. If you know any other method to change the MAC address, share them in the comment below.

You May Also Like


Karthik Vee August 20, 2016 - 9:29 pm


Bob Beezea February 7, 2019 - 8:08 pm

Since I couldn’t find a netplan solution I’m going write up a udev rule. Still interested in a netplan solution if there is one.
Thank you.

kcdtv August 14, 2019 - 2:10 pm

ifconfig is deprecated since more than ten years. ( check http://inai.de/2008/02/19 ) I am always shocked when I read your themes and see that you always mix deprecated and up to date command lines. In order to get the mac adresses of your interfaces you should use something like: ip a | grep ether . It is even faster than writing ifconfig…. Also i don’t see the point of making a new theme in 2019 about things that are all over the internet, if you do so at least update it…. It is time to wake up guys instead of publishing for publishing…

Max Power August 15, 2019 - 5:34 am

What about using a different MAC for a wireless network card? What is the procedure?

Juan January 4, 2021 - 2:31 pm

I changed my mac address but i’m not able to connect to internet anymore, how to fix it ?

sk January 4, 2021 - 9:59 pm

Changing mac address will not persist across reboots. Just reboot your system and your network card will get its original mac id.


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More