Friday 7 December 2007

How to change MAC-address of Ethernet card

Sometimes changing MAC-address of a network card is needed. For example, when it used for authorisation by internet provider. This is relatively simple yet unobvious in a first time procedure, but here are some examples.



Temporary MAC-address change
Go to the terminal and type:
sudo ifconfig eth0 hw ether xx:xx:Xx:xx
and MAC-address change and will stay until reboot. If you wish to change
MAC-address permanently, you need to do this:


Permanent change of
MAC-address
In Debian, for example, go to  /etc/network/if-pre-up.d/ and create file from root named pre-up.
Let`s write to them strings like this:
#! /bin/sh
ifconfig eth0 hw ether 00:00:00:00
Change zeroes by needed
MAC-address. To make changes active immediately, restart of network subsystem is required:
/etc/init.d/networking restart
In first time, following diagnostic messages are expected to appear:
# /etc/init.d/networking restart
Setting up IP spoofing protection: rp_filter.
Reconfiguring network interfaces...SIOCDELRT: No such process
ifup: interface lo already configured
SIOCSIFHWADDR: Device or resource busy
run-parts: /etc/network/if-pre-up.d/pre-up exited with return code 1
done.
No problems, repeat command, and it will execute smoother:
notebeast:/home/beast# /etc/init.d/networking restart
Setting up IP spoofing protection: rp_filter.
Reconfiguring network interfaces...ifup: interface lo already configured
done.
Here we go, the MAC-address is changed permanently.


How to find out MAC-address of network card in Linux
It's very simple, just type:
sudo ifconfig
and you see something like this:
eth0 Link encap:Ethernet HWaddr 00:0A:E4:53:AA:2D
inet addr:10.26.49.77 Bcast:10.26.63.255 Mask:255.255.240.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:208554 errors:0 dropped:0 overruns:0 frame:0
TX packets:125071 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40664531 (38.7 MiB) TX bytes:45919980 (43.7 MiB)
Interrupt:21 Base address:0x4c00

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:18511 errors:0 dropped:0 overruns:0 frame:0
TX packets:18511 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:537155 (524.5 KiB) TX bytes:537155 (524.5 KiB)

One's MAC-address is emphased by red font colour.


Yet another tips to change MAC-address

For example, MAC-address in Gentoo can be changed in /etc/conf.d/net


mac_eth0="00:50:8D:63:41:DE"
config_eth0=( "192.168.100.37 netmask 255.255.252.0" )
routes_eth0=(
"default via 192.168.100.1"
)

Or edit /etc/network/interfaces adding one string:
pre-up ifconfig eth0 hw ether 00:00:00:00:00:00
Indeed, there are loads of variants, because it is Linux :-)

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
hwaddress ether xxxxxxxxxxxx


Conclusion
This post can be useful to those who connected to Internet via provider authorising by MAC-address.

4 comments:

Anonymous said...

I tried to change my MAC address like this
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
hwaddress ether xxxxxxxxxxxx
but it didn't work, my MAC remains unchanged. Any suggestions regarding this method? Some improvements? Thank you in advance.

virens said...

I tried to change my MAC address like this
This method not always get results - try other methods. Some network adapters doesn't allow to change MAC.

but it didn't work, my MAC remains unchanged. Any suggestions regarding this method?
Too few information. What network card used? What distribution?

Try change MAC directly by ifconfig.

Angel CaĆ­do said...

Worked for me. After installing Icecast2 in LMDE my internal network card MAC Address changed within the OS environment; I followed the steps described above and now my MAC Address changes to the correct one. Better than having to reinstall.
Thank you so much.

Anonymous said...

if you don't change the X bit, the script is probably not executed, right?