How to restore MAC address in Linux?

21,710

Solution 1

You can get your vendor-specified hardware MAC address using ethtool:

ethtool -P eth0

To reset the MAC address to this value, you can do something like:

sudo ifconfig eth0 hw ether $(ethtool -P eth0 | awk '{print $3}')

Solution 2

2021.05.25

The easiest is to use macchanger utility. It is available for every GNU/Linux distribution.

STEP 1: Disable the network interface you want to restore. Let's say eth0

# ip link set eth0 up

STEP 2: Restore MAC address using macchanger

# macchanger -p eth0

STEP 3: Enable the interface

# ip link set eth0 up

This is it!

Solution 3

[rooted] assuming wlan0

...(to find driver)
airmon-ng | awk '/wlan0/ {print $4}' ...or

airmon-ng | awk '/wlan0/ {print $3}' ...or just

airmon-ng ..and look under 'driver'

...(to restart driver)
ifconfig wlan0 down

modprobe -r rt2800usb <=Replace (rt2800usb) with your driver

modprobe rt2800usb <=Replace (rt2800usb) with your driver

ifconfig wlan0 up

This is how I do it. I made a script for this and use it with a couple of my programs. If that's the route you take, put a 'time.sleep(3)' {or whatever sleep command} before bringing the interface back up.

Solution 4

Assuming eth1:

grep "eth1" /var/log/*log | egrep "([0-9a-fA-F]{2}:){5}"

could find something in the logs {daemon,kern,syslog}.log on my system.

Share:
21,710

Related videos on Youtube

narayanpatra
Author by

narayanpatra

Updated on September 18, 2022

Comments

  • narayanpatra
    narayanpatra almost 2 years

    I have changed my MAC address in my Linux machine using ifconfig. Now the problem is I have not saved my original MAC address. I want to restore it without rebooting.

    Is there a way to do it?

    • new123456
      new123456 about 13 years
      Any reason no to reboot?
    • narayanpatra
      narayanpatra about 13 years
      Running half a dozen applications. Dont want to close them.
    • evan.bovie
      evan.bovie about 13 years
      Run this?: sudo ifdown interface && sudo ifup interface Or maybe: sudo /etc/init.d/networking restart
    • narayanpatra
      narayanpatra about 13 years
      @emb : did not work.
  • narayanpatra
    narayanpatra about 13 years
    can you elaborate the first method. The second one did not work.
  • evan.bovie
    evan.bovie about 13 years
    The <NICmodule> would be what ever kernel module the NIC is using. e.g. e1000 You can see what you have with this guide.
  • sealz
    sealz about 13 years
    Do you know what module your network card uses? This will just remove the module and then put it back (hopefully with the right MAC)
  • paradd0x
    paradd0x about 13 years
    @narayanpatra Did you replace interface with what you use to access the internet? In most cases it's eth0
  • narayanpatra
    narayanpatra about 13 years
    @thiago : Ya, i did that.