13

I tried to change the MAC address in a ubuntu VM (virtualbox), but after that it threw lots of errors during boot, and then I had no internet connection.

Then I saw that the interface was renamed to eth1, so I edited /etc/network/interfaces to change eth0 to eth1, rebooted (didn't know how to restart the network), and boot was now faster and internet worked fine.

But now after every time I log in, I get 1 or 2 error messages that say nothing, they only ask me if I want to report them.

So I was wondering, is there was a proper way to change MAC address, to avoid these issues?

2
  • 1
    There are a number of factors involved in changing a mac address, in a VM or otherwise. Can you explain why you want to change the mac, it might help with finding the best solution (meta.stackexchange.com/questions/66377/what-is-the-xy-problem)
    – Paul
    Commented Jul 4, 2012 at 4:53
  • @Paul I'm trying to learn how different programs track your activity, how to do it, and how to avoid it. Eg: IP, cookies, browser fingerprinting, etc. Now I want to see how some programs respond to a MAC address change. Commented Jul 4, 2012 at 6:55

2 Answers 2

15

You are very likely using the "correct" method to change the MAC address, if you are doing this in the advanced network settings in VirtualBox. However, a temporary change as in the other answer by Zuul may be best for your purposes, as it will change the MAC without causing too many additional problems - however it will not survive a reboot.

Changing it in VirtualBox will of course survive a reboot, but the issue you are facing is with udev. This is the process that looks at hardware and sets that hardware up in /dev (or whatever else might need to be done). One of the things it does by default is to try to maintain persistent names for network interface cards [nics]. This is because when you have multiple nics, you want them to always have the same ethX name, so that your /etc/network/interfaces configuration targets the right nic each boot. The OS cannot rely on them just being physically in the same spot each time - you may move them around for example, or some systems do not report their physical connections in the same sequence each boot.

So udev uses persistence rules based on the MAC address of the network card. If it has an entry for eth1 with a known MAC address and a card appears with a different MAC address it will allocate a different ethX device name to the interface.

To counter this, you just need to update the udev rules. Edit:

vi /etc/udev/rules.d/70-persistent-net.rules

and look for the line with your current MAC:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="11:22:33:44:55:66", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

If you change the MAC address here to the new one you chose in VirtualBox settings, then it will retain the same ethX dev number next boot.

The best sequence would probably be to edit it here first, then shutdown the VM, then edit the VB MAC setting, then boot up.

4
  • Editing the file manually didn't work for me, but I remembered reading that you can remove this file allthogether and after rebooting, it's generated automatically. And that actually worked :) +1 for showing the file location. Commented Apr 30, 2013 at 7:31
  • @Paul Why is it then, that I can clone a Linux system from one physical machine to another of same type (but different MAC addresses) and do not run into such trouble?
    – arney
    Commented Jun 12, 2013 at 13:59
  • 1
    @arney I think that's because it is a different NIC altogether, not only the MAC-address changes. In the file that is mentioned by Paul, you can see: ATTR{dev_id}=="0x0". This is bound to be different.
    – MarioDS
    Commented Jun 12, 2013 at 14:22
  • @arney I think you are right Arney, if the nic doesn't exist, then the udev rule won't be applied. This is the same as if it were a new machine. Without the errors it is hard to say. But deleting the persistence rules will help if it is udev.
    – Paul
    Commented Jun 14, 2013 at 1:43
8

You can change the MAC address with 4 simple steps using ifconfig:

Open a terminal (keyboard shortcut: ctrl + alt + t)

  1. Find the current mac address:

    ifconfig | grep HWaddr
    
  2. Shut down the interface (assuming it to be eth0 for the next steps):

    ifconfig eth0 down
    
  3. Set the new mac address:

    ifconfig eth0 hw ether 00:1E:68:35:FF:91
    
  4. Flag causes the interface to be activated:

    ifconfig eth0 up
    

Now you can recheck your interface mac address:

ifconfig eth0 |grep HWaddr

Note: You can choose any 48 bits hexadecimal address as your MAC address.


For the purpose of completeness, you can combine steps 2 and 3 into one line:

ifconfig eth0 down hw ether 00:00:00:00:00:01
1
  • @DownVoter: If there is a problem with my answer, a comment would go a long way as to allow me to improve it! Tks.
    – Zuul
    Commented Jul 29, 2013 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .