Spoof or change MAC address in Linux

How-to-change-MAC-address-in-Linux-blackMORE Ops -3

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 distros. 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!

Temporarily change MAC Address

All example are for eth0 interface. If you have a different interface you can find them easily with the following command

ifconfig -a

I’ve also used /etc/init.d/networking to make it more generic. Experienced users can also try the following command

service networking stop
service networking start

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.

 /etc/init.d/networking stop
 ifconfig eth0 hw ether 02:01:02:03:04:08
 /etc/init.d/networking start

Test

Try the following in Terminal to confirm if your MAC address has been changed:

ifconfig eth0

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 /etc/init.d/network instead of /etc/init.d/networking.

If you have iproute2 utilities installed, you may prefer to use the “ip” command, as follows:

/etc/init.d/network stop
ip link set eth0 address 02:01:02:03:04:08 
/etc/init.d/network start

To confirm your setting, you may prefer to execute ip link ls eth0 or ip addr ls eth0 instead of ifconfig eth0.

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 desktop\server, etc.) you can make changes permanent” across reboots by adding an appropriate entry to the /etc/sysconfig/network/ifcfg-ethN file (ifcfg-eth0 for the first Ethernet interface config file, ifcfg-eth1 – for the second, etc.):

LLADDR=12:34:56:78:90:ab

In Red Hat Enterprise Linux (RHEL) and other similar systems (Fedora, CentOS, etc.) an easy way to make changes permanent across reboots is to add an appropriate entry to the /etc/sysconfig/network-scripts/ifcfg-ethN file (ifcfg-eth0 for the first Ethernet interface config file, ifcfg-eth1 – for the second, etc.):

MACADDR=12:34:56:78:90:ab

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/net for each Ethernet card. Example for the eth0 device:

mac_eth0="12:34:56:78:90:ab"

You can also use the tool GNU MACChanger apt-get install macchanger to 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. Please share and RT.

Check Also

How to fix You can’t access this shared folder because your organization’s security policies block unauthenticated guest access error on Windows 11

If you have the following error on Windows 11 “You can’t access this shared folder …

How to unhide menu bar in Virtualbox - blackMORE Ops - 2

How to unhide menu bar in Virtualbox

So I went in and hid the top menu bar and bottom status bar in Virtualbox. After they disappeared, now I cannot find out how to unhide those. Took me a little bit time to figure out, hence this post so that I don't forget it and someone else having the same to unhide menu bar in Virtualbox can find this.

5 comments

  1. Could you clarify something a little? So on an Ubuntu system with a network interface named “wlan0”, I would add something like this:

    iface hwaddress wlan1 :NE:WM:AC:AD:DR:ES

    Is that correct?

  2. It is interesting that admin can change MAC address but could be useless. There is a problem in Linux kernel and some cheap USB network adapters without HW MAC address get the same MAC address assigned (00:e0:4c:53:44:58) by Linux driver. There are many cheap and cool USB adapter based on RD9700 (DM9601 or AX88x72A clone) on eBay. These work fine under Windows but driver under Linux assign them the same MAC address, so you cannot have more than one such adapter in your local LAN. You can change MAC address with instructions described in the article but the same problem has Android (powered by Linux kernel) and you cannot change MAC address on Android device without root rights…

  3. Thank you for all those info,and have you some idea about amd/ati graphic driver work in kali 1.0.7 i686 platform?here I came with if does help in some way:
    root@localhost:~# ifconfig wlan0 down
    root@localhost:~# macchanger -m 00:11:22:33:44:55 wlan0
    Permanent MAC: 00:16:ce:70:80:52 (Hon Hai Precision Ind. Co., Ltd.)
    Current MAC: 00:16:ce:70:80:52 (Hon Hai Precision Ind. Co., Ltd.)
    New MAC: 00:11:22:33:44:55 (Cimsys Inc)
    root@localhost:~# ifconfig wlan0 up

  4. I usualy do this:

    /etc/init.d/network-manager stop

    macchanger -r wlan0

    /etc/init.d/network-manager start

Leave your solution or comment to help others.

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

Discover more from blackMORE Ops

Subscribe now to keep reading and get access to the full archive.

Continue reading

Privacy Policy on Cookies Usage

Some services used in this site uses cookies to tailor user experience or to show ads.