Table of Contents
Why to change MAC Address
When it comes to networking, you've probably heard of the term MAC addressed a lot. MAC Address is a physical identity assigned to each interface. Now you may wonder when the MAC Address is already assigned to an interface then why would we want to change it? Well there can be a number of scenarios, speaking from my personal experience
- We had a very old rack server where we failed to installed RHEL 8 and the MAC address of the interfaces from this server kept changing after every reboot. So we decided to update the PCI ID of each interface using udev rule bundled inside initrd to overcome this issue.
- For PXE boot we perform network based installation. Now this should not be a problem when we are using DHCP but if you want to use static IP then you must define the MAC Address of the interface and the IP to be assigned. Now imagine you have 100s of servers, so connecting to each one and getting the MAC can be nasty so we can just change the MAC address of these servers as per our need and then just use them to perform PXE boot.
In this tutorial, I will cover what we mean by MAC address, what it's used for, and how to change it. We will use Kali Linux to demonstrate the steps from this article.
Overview on MAC Address
- MAC address stands for Media Access Control, and it's a permanent, physical, and unique address assigned to network interfaces by the device manufacturer.
- So whether you have a wireless, wired, or Ethernet, each of these network cards comes with a specific address unique to this card. There are no two devices in the world that would have the same MAC address.
- This address will always be the same to this specific device; even if you unplug it from your computer and connect it to another computer, this network device will always have the same address.
- Not only that but the MAC address is often used by filters to prevent or allow devices to connect to networks and do specific tasks on the web.
- Changing your MAC address to another device's MAC address will allow you to impersonate this device and will enable you to do things that you might not be able to do.
- So you'd be able to bypass filters or connect to networks that only specific devices with specific MAC addresses can relate to, and you will also be able to hide your identity. Now changing the MAC address is very simple, so let me show you how to do that.
Method-1: Change MAC Address of Network Adapter (Non-Persistent)
Step 1: List Network Interfaces
First, I will use the
ifconfig command to list all the network interfaces available on my Kali machine. What I mean by network interface is any device that allows us to connect to a network.
An example is a Wi-Fi card or an Ethernet card, and so on. So you can see first of all we have
eth0, which is a virtual interface created by virtual box when we set Kali to use NAT network.
You can see the interface name is eth0, and you can see it has an IP address because, as I said, it's connected to a network.
If we go here, we can see it saying Wired Connected. The interface represents the wired network that Kali is connected to, which is a virtual NAT network.
You can also see the netmask, the broadcast, and an essential piece of information: the ether, which is the MAC address of this virtual interface.
Now, you can see similar information for my other two interfaces, the lo and the wlan0. The only thing is you can see for both of these interfaces. We do not have an IP address. And the main reason for that is that none of these interfaces is connected to a network.
lo is the default interface created by Linux, and
wlan0 is my genuine wireless adapter. I can use it to connect to Wi-Fi networks. But if I go on the web in here, you'll see Wi-Fi is not connected because I didn't connect to any network, and that's why it does not have an IP address.
Now, this doesn't matter because we want to change the MAC address, which is again shown under the ether part, similar to what you see here for
Step 2: Disable Interfaces
Now, to change any of the values you see here, you first have to disable the interface. In this example, we want to change the MAC address to represent it by the ether, and the value is right here.
To disable an interface, we're going to do
ifconfig followed by the interface name,
wlan0 in my example, followed by down to disable it.
Now, if I hit Enter, you'll see the command runs with no errors, so it means that it got correctly executed. And the next thing that we need to do is change the option that we want to change. And in this example, we want to change the ether, which is the MAC address.
Step 3: Change MAC Address
First, we're going to type
ifconfig, type the interface that we want to change, one of its options, then type the option we want to change. And what we want to change is the hardware address, so we're going to do hw ether. Then we're going to give it the lesson that we want to change the MAC address.
For this example, I'm going to use
00:89:76:88:82:33. Very, very simple command, we're doing
ifconfig wlan0 to select the interface that we want to change its option, we want to set the hardware address, and we want to put this address to this specific address.
So you can use any address that you want, following the same format shown here. Just make sure your address starts with
00. So I'm going to hit Enter, and again, we don't see any error messages, so it means the command got appropriately executed.
And finally, we need to enable the interface because we disabled it by doing
ifconfig wlan0 down, so we need to do
ifconfig wlan0 up to allow it. Now the interface is enabled, and if we do ifconfig again, and look at the ether part here, you can see that it is changed to the MAC address that we specified.
Step 4: Verify the new MAC Address
Now, this is done, and your MAC address has changed. Now, you can go ahead and start using the interface, and it'll appear to have this MAC address instead of its original MAC address. And like I said, this can be useful in so many scenarios.
Now, keep in mind, the MAC address will revert to the original one once you restart the computer because we're only changing the MAC address in memory. We're not changing the physical MAC address.
Method-2: Change MAC Address of Network Adapter (Persistent)
In this section we will change MAC Address of a network adapter permanently which will be persistent across reboots.
Step-1: Install Macchanger on Linux
Install macchanger on Linux Mint:
$ sudo apt install macchanger
Step-2: List available network interfaces
It’s important to know the network interface you are working with. Execute the command ifconfig to see all available network interfaces in system.
Once we have the interface name for which we wish to change the MAC Address, we can also use following command show the MAC Address of the respective interface:
$ sudo macchanger -show eth0
Step 2: Assign a random MAC Address
-r option to get a random MAC address and specify the name of your network interface.
$ sudo macchanger -r eth0
Step 3: Assign static MAC Address
If you need to use a specific MAC address, you can do that with the
-m option and the following command syntax.
$ sudo macchanger –m 34:3c:56:d4:e3:23 eth0
The output should show your current and new MAC address that is assigned from macchanger.
To verify the change, try running the
ip a command
$ ip a
You might already know that the IP address is used on the internet to identify computers and communicate between devices on the internet. The MAC address is used within the network to identify devices and transfer data between devices. Each piece of data or packet sent within the network contains a source MAC and a destination MAC.
Therefore, this packet would flow from the source MAC to the destination MAC. So because this is a unique physical address to each interface, to each network device, and because it is used to identify devices, changing it will make you anonymous on the network.
Hacking/Tools/Network/Changing Your MAC Address/Linux
1 thought on “Solved: Change MAC Address in Linux [Temp & Persistent]”
sudo macchanger –m 34:3c:56:d4:e3:23 eth0
this command does not work with my Ubuntu 20.04 after rebooting my PC
by the way I am using netplan with workd in it to set my netowrk.