Home Linux DistributionsCentOS How To Change MAC address In Linux
change mac address in linux

If you don't want to expose the real MAC addres when you are connected with a public WiFi hotspot, 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

Or,

$ 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

Or

$ 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

Or

$ 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.

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 127.0.0.1/8 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 192.168.1.105/24 brd 192.168.1.255 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.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

4 comments

Karthik Vee August 20, 2016 - 9:29 pm

Informative

Reply
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.
Regards,
Bob

Reply
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…

Reply
Max Power August 15, 2019 - 5:34 am

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

Reply

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. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More