btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Spoofing Mac Address on Stretch

Wed Jul 11, 2018 9:05 pm

Hope the following may be useful to somebody.

I use USB to LAN adapters on several Pi Zeros. These work well but one thing to overcome is that the cheap units come with same Mac address which stops multiple units being used on the same network.

Previously I had spoofed the Mac Address on Jessie builds by inserting the following lines in /etc/network/interfaces

Code: Select all

allow-hotplug eth0
iface eth0 inet dhcp
    hwaddress ether 00:e0:4c:53:44:59
where eth0 was the interface name.

This seems to have stopped working on Stretch and for me had the effect of stopping the boot completing until the lines are removed.

I tried various other methods for spoofing without success until I used the udev rules method. Even this was problematic as most of the instructions don't cover everything.

The technique is to create a file /etc/udev/rules.d/75-mac-spoof.rules with the contents

Code: Select all

ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="XX:XX:XX:XX:XX:XX", RUN+="/sbin/ip link set dev %k address YY:YY:YY:YY:YY:YY
where the XX mac address is the original mac address (as reported by ipconfig) and the YY mac address is the new spoofed one. %k gets substituted with interface name.

Most descriptions of this have the RUN using /usr/bin/ip but that doesn't work as it is located under /sbin

The second bit that delayed me is that the ATTR{address} match is case sensitive so the XX Mac address needs to be the exact match (lower case for my adapters). The YY address in the command does not seem to be case sensitive.

User avatar
DougieLawson
Posts: 35805
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Spoofing Mac Address on Stretch

Thu Jul 12, 2018 7:15 am

If you want to spoof the MAC for the built-in eth0 adapter add

Code: Select all

smsc95xx.macaddr=aa:bb:cc:dd:ee:ff
to /boot/cmdline.txt [obviously with a more sensible MAC address].
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Spoofing Mac Address on Stretch

Thu Jul 12, 2018 10:13 am

Yes. That still works on stretch for the built in unit, but they have unique mac addresses so the need to spoof is less.

My use case was for external usb LAN adapters where the cmdline.txt method is not applicable.

MarcusH
Posts: 1
Joined: Mon Sep 03, 2018 1:56 pm

Re: Spoofing Mac Address on Stretch

Mon Sep 03, 2018 9:31 pm

Thanks btidey for a very helpful post!!!!!

Some comments:
  • Typo correction:
    btidey's wrote:

    Code: Select all

    ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="XX:XX:XX:XX:XX:XX", RUN+="/sbin/ip link set dev %k address YY:YY:YY:YY:YY:YY
    You are missing the last double-quote. Full line below:

    Code: Select all

    ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="XX:XX:XX:XX:XX:XX", RUN+="/sbin/ip link set dev %k address YY:YY:YY:YY:YY:YY"
  • You can also go the systemd.link route.

    Code: Select all

    # /etc/systemd/network/10-dm9601.link
    # set the MAC address for anything with Driver=dm9601
    [Match]
    Driver=dm9601
    
    [Link]
    MACAddress=00:e0:4c:53:45:03
    

Return to “Networking and servers”