2

I figured out how to change my mac address of my network card:

sudo ip addr                                    # Show details
sudo ifconfig eth0 down                         # deactivate network card
sudo ifconfig eth0 hw ether DESIRED_MAC_ADDRESS # change mac address
sudo ifconfig eth0 up                           # activate network card
sudo ip addr                                    # show details again

What would be the best way to make this a script which I could start each time I need this modification? Also where do I have to put this generated script? What is the standard folder for this?

I don't want it to be started every time Ubuntu starts. (But it would be nice to know how this is done, though. Where would be the best place to store it in that case?)

Appreciate any suggestions!

3
  • Not answering your question, but I'd take a look at program macchanger. Changing and resetting your MAC is as simple as sudo macchanger -m 00:11:22:33:44:55 eth0 and sudo macchanger -p eth0.
    – htorque
    Dec 25, 2011 at 20:44
  • Thanks for this hint, but I already tried macchanger. It doesn't work for me. That's why I figured out the alternative above.
    – Aufwind
    Dec 25, 2011 at 20:53
  • I would but it in ~/bin and add that to path, but I'm a bit paranoid. Dec 25, 2011 at 23:14

2 Answers 2

2

Not really sure what you mean by 'the best way'. The regular, easy and practical way would be to copy/paste the commands into a text file named, for example, best_way, save it anywhere you want, for example, the home folder, and, ... believe it or not, that's it.

To run it, cd to the folder with the file, then sudo bash ./best_way.

PS: Since you'll be using sudo to run the script, there is no need to precede each command with sudo.

4
  • This approach didn't work. I assume it takes some time for ifconfig eth0 down to be processed and to deactivate the network card. Is there a way to tell the script to wait until the process is done, then execute the next line?
    – Aufwind
    Dec 25, 2011 at 20:59
  • 1
    Try the sleep command (in seconds, e.g. sleep 1.23 for 1s and 230 ms).
    – htorque
    Dec 25, 2011 at 21:04
  • @Aufwind: I don't think ifconfig command is asynchronous, i.e. it does not return control to the calling script until it finished what it was doing. So there's no need to do anything special to ensure the process is done. If you have any problems they're likely caused by something else
    – Sergey
    Dec 25, 2011 at 22:33
  • +1. I have a similar script that does what it is supposed to do without having to delay it with sleep. Dec 25, 2011 at 22:43
2

The debian way of setting MAC address is to specify hwaddress option in the /etc/network/interfaces file.

It's not well documented, but you can find a lot of useful information here.

You must log in to answer this question.

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