Monday, November 24, 2014

Change MAC Address on Linux (Ubuntu / Debian)

Temporary MAC Address Change

When you change the MAC address for an interface, you need to have the network interface disabled (down) and than to set the new MAC.

You can do both this things with the command:

$ sudo ifconfig eth0 down hw ether AA:BB:CC:DD:EE:FF && ifconfig eth0 up

This sets down the eth0 interface, changes the mac to AA:BB:CC:DD:EE:FF and turns the interface back down.

Or, do it in the old fashioned way:

$ sudo ifconfig eth0 down
$ sudo ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF
$ sudo ifconfig eth0 up

Read more about the ifconfig command here.

 

Permanent MAC Address Change

To set the hardware address (MAC), open the /etc/network/interface file in your favourite text editor:

$ sudo vim /etc/network/interfaces

After the network interface configuration, paste this line: hwaddress ether AA:BB:CC:11:22:33.
Note: AA:BB:CC:11:22:33 is just a sample, replace it with the MAC address you want to set for your interface.

Example, with dhcp enabled network interface:

auto eth0
iface eth0 inet dhcp
hwaddress ether AA:BB:CC:11:22:33

Example, with a network interface having a static ip:

auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
hwaddress ether AA:BB:CC:11:22:33

To apply the MAC change, restart the network interface:

$ sudo /etc/init.d/networking restart

Based On:

No comments: