Thursday, February 19, 2009

Changing MAC address in Linux

Changing MAC addresses of network adapters on machines have become a mundane thing these days. For those using debian and ubuntu there are multiple ways to achieve the same.

ifconfig hw

Example:

# /etc/init.d/networking stop
# ifconfig eth0 hw ether 00:00:00:A9:0A:3C
# /etc/init.d/networking start

The MAC address set via this way would be temporary and lost next time you reboot. The more better and persistent solution is to add the following line with interface settings in /etc/network/interfaces.

hwaddress

Example:

iface eth0 inet static
address x.x.x.x
netmask 255.x.x.x
gateway x.x.x.x
hwaddress ether 00:00:00:A9:0A:3C

Don't forget to restart network using /etc/init.d/networking restart, or rebooting machine after this. There is another command-line tool available these days named macchanger, a GNU/Linux utility for viewing/manipulating the MAC address of network interfaces, which can also be used apart from the above mentioned two methods.

# /etc/init.d/networking stop
# macchanger -m 00:00:00:A9:0A:3C eth0
# /etc/init.d/networking start

No comments: