Changing MAC address in Linux
This guide takes you through step by step procedures on How to change MAC address in Linux. I’ve tried to make it generic to cover most Linux distroes. If you have a different option, please comment and I will include it in my guide.
Under GNU/Linux, the MAC address of a network interface card (NIC) can be changed by following the procedures below.
NOTE: MAC addresses used within this article are provided for example only. Substitute according to your requirements.
NOTE: Commands below MUST be executed with root privileges (e.g. prepended with sudo if required), in order for things to work!
All example are for eth0 interface. If you have a different interface you can find them easily with the following command
I’ve also used
/etc/init.d/networkingto make it more generic. Experienced users can also try the following command
service networking stop
service networking start
Temporarily change MAC Address
Do the following from command line to change you MAC address temporarily. This way it will revert back to original MAC when you reboot your machine.
ifconfig eth0 hw ether 02:01:02:03:04:08
Try the following in Terminal to confirm if your MAC address has been changed:
The above should work on Debian, Ubuntu, and similar distributions. Alternatively, under RHEL/Fedora and possibly other GNU/Linux distributions (incl. CentOS and Scientific Linux), to disable and restart networking, one must stop and start
If you have
iproute2utilities installed, you may prefer to use the “
ip” command, as follows:
ip link set eth0 address 02:01:02:03:04:08
To confirm your setting, you may prefer to execute
ip link ls eth0or
ip addr ls eth0instead of
NOTE: You may not be able do this if using a DSL modem (depending on modem vendor or ISP).
Permanently change MAC Address
Now let move to make these changes permanent. Following guide is to enable your change survive a Reboot.
In openSUSE and other SUSE-based systems (SUSE enterprise desktopserver, etc.) you can make changes permanent” across reboots by adding an appropriate entry to the
/etc/sysconfig/network/ifcfg-ethNfile (ifcfg-eth0 for the first Ethernet interface config file, ifcfg-eth1 – for the second, etc.):
In Red Hat Enterprise Linux (RHEL) and other similar systems (Fedora, CentOS, etc.) an easy way to make changes permanentacross reboots is to add an appropriate entry to the
/etc/sysconfig/network-scripts/ifcfg-ethNfile (ifcfg-eth0 for the first Ethernet interface config file, ifcfg-eth1 – for the second, etc.):
Note: in the file is a value HWADDR – This is not the same thing. Use MACADDR for permanent changes.
from CentOS Interface Configuration Files
The HWADDR “directive is useful for machines with multiple NICs to ensure that the interfaces are assigned the correct device names regardless of the configured load order for each NIC’s module. This directive should not be used in conjunction with MACADDR.”
The MACADDR “directive is used to assign a MAC address to an interface, overriding the one assigned to the physical NIC. This directive should not be used in conjunction with HWADDR.”
Upper and lower case letters are accepted when specifying the MAC address, because the network function converts all letters to upper case.
You can test changes without restarting the system by executing:
service network restart
(WARNING: doing this will break all existing network connections!)
On Debian, Ubuntu, and similar systems, place the following in the appropriate section of
/etc/network/interfaces(within an iface stanza, e.g., right after the gateway line) so that the MAC address is set when the network device is started:
hwaddress ether 02:01:02:03:04:08
On Gentoo you may achieve the same result by adding an entry to the global configuration file
/etc/conf.d/netfor each Ethernet card. Example for the eth0 device:
You can also use the tool GNU MACChanger
apt-get install macchangerto change the MAC address under GNU/Linux.
To change MAC address during boot time with MACChanger, add the following line to your
/etc/network/interfaces(example for the eth0 interface):
pre-up macchanger -m 12:34:56:78:90:AB eth0
Thanks for reading.