changing MAC address in /etc/network/interfaces

Asked by Pierre Frenkiel

I need to change the MAC address of a PCMCIA card. Doing
this via macchanger or ifconfig works, but that needs to
add or modify a startup script.
I saw a lot of posts telling how to do that in /etc/network/interfaces, but that doesn't work for me: after boot, the
interface still has its original address, and if I try:
  ifconfig eth3 down
  ifup eth3
I always get a message
   SIOCSIFHWADDR: Device or resource busy - you may need
   to down the interface
Idem after "ifdown eth3"
Idem after removing NetworkManager

What did I miss?

Config: Ubuntu 8.04

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Jim Hutchinson
Solved:
Last query:
Last reply:
Revision history for this message
Bhavani Shankar (bhavi) said :
#1

sudo gedit /etc/network/interfaces

f you have dhcp enabled, it will look like this:

    auto eth0
    iface eth0 inet dhcp

Just add another line below it to make it look something like this:

    auto eth0
    iface eth0 inet dhcp
           hwaddress ether 01:02:03:04:05:06 <--- (The mac address)

    sudo /etc/init.d/networking restart

You will need to restart networking or reboot to take effect.

Regards

Revision history for this message
Pierre Frenkiel (pierre-frenkiel) said :
#2

It's difficult to keep cool when you see that the guy who
answers has obviously not read the question!!
Please see above, or here if you can't read more than 1 line:

   after boot, the interface still has its original address

Revision history for this message
Bhavani Shankar (bhavi) said :
#3

Please remember that we are volunteers who are answering here and please keep in mind the CoC

http://www.ubuntu.com/community/conduct

gedit etc/init.d/bootmisc.sh

At the bottom of the file add the following:

killall dhclient
killall dhclient3
ifconfig eth0 down
ifconfig eth0 hw ether MY:MA:CA:DD:RE:SS <--- The mac address you have set
ifconfig eth0 up
/sbin/dhclient
/sbin/dhclient3

and restart and see....

Regards

Revision history for this message
Pierre Frenkiel (pierre-frenkiel) said :
#4

Is it a joke? We are not on April 1.
I agree to follow th CoC, and in particular
"Be respectful", but I think it is not actually respectful
to provide answers which has nothing to do with the question.
Once again, I remind the subject of my question:
   "changing MAC address in /etc/network/interfaces"
and I wrote (as anybody can verify looking above):
   "Doing this via macchanger or ifconfig works"

Revision history for this message
Best Jim Hutchinson (jphutch) said :
#5

Pierre, I realize it's frustrating to have a problem and not get an answer that helps, but remember that not everyone here is a native English speaker and sometimes we don't always understand. Bhavani helps here a lot and I think he deserves credit for trying. If his solution doesn't work just state that fact and reopen the question.

As for your question, a bit of googling suggests it may not be a cut and dry issue - in other words it works for some and not others. If you have followed directions like in this thread http://ubuntuforums.org/showthread.php?t=316126 and it isn't working you may need to pursue a different course. Since macchanger works, why not add the macchanger command to the /etc/network/interfaces file? You may also need to stop using NetworkManager if you do. In recent versions of Ubuntu NetworkManager controls the interfaces and if you make changes to the /etc/network/interfaces file they may conflict with NetworkManager. That may also be why your original changes didn't work.

HTH

Revision history for this message
Pierre Frenkiel (pierre-frenkiel) said :
#6

> Pierre, I realize it's frustrating to have a problem and not get an
> answer that helps

   Jim, that is not the problem: I know it is not always easy to help people.
   But in that case, I said:
      Doing this via macchanger or ifconfig works,
      but that needs to add or modify a startup script.
   and he tells me how to use ifconfig and how to modify a script!!
   (modifying an existing script needs a special mechanism to keep
   your modifications after any system update)

> http://ubuntuforums.org/showthread.php?t=316126
   I missed it while googling, but that was the good one to look at.
   the beginning is identical to all other posts:
       hwaddress ether 01:02:03:04:05:06
   and that doesn't work
   but the good one is at the end:
   in interfaces, add:
       pre-up ifconfig eth0 hw ether xxxxxx
   and that works, even with NetworkManager.
   A better solution is to add a new script in /etc/network/if-pre-up.d, with
          #!/bin/sh
          ifconfig eth0 hw ether xxxxxx
   This one will never be overwritten by a system update.

> You may also need to stop using NetworkManager if you do
  I said "Idem after removing NetworkManager" ...

--
Pierre

Revision history for this message
Pierre Frenkiel (pierre-frenkiel) said :
#7

Thanks Jim Hutchinson, that solved my question.