0

I wonder how it is possible to change the mac address of a wifi dongle using systemd.

I tried this but without success:

cat > /etc/systemd/network/00-wlx*********.link <<EOF
[Match]
Name=wlx**********
[Link]
MACAddress=xx:xx:xx:xx:xx:xx
jake
  • 1,347
  • 10
  • 23
  • Have you tried using the existing Macaddress in the match instead as per this answer - is there any message in the logs to help you determine why this hasn't worked – Jaromanda X Dec 09 '18 at 09:14
  • Maybe use Interface instead of Name. This works for me although strangely enough I can't find it in the docs as a valid parameter. – Dirk Dec 09 '18 at 10:02

1 Answers1

2

For a *.link file there is no option Name= defined in section [Match]. Instead you can use OriginalName=. But according to man systemd.link there are some quirks with it:

A whitespace-separated list of shell-style globs matching the device name, as exposed by the udev property "INTERFACE". This cannot be used to match on names that have already been changed from userspace. Caution is advised when matching on kernel-assigned names, as they are known to be unstable between reboots.

Best is to use MACAddress= as @Jaromanda X suggested but there are other options (see man page, there are also some examples).

If you already have a systemd unit for example to configure an interface then you can simply add a statement to the [Service] section like:

ExecStartPre=/sbin/ip link set wlan0 address b8:27:eb:06:e8:88

Instead of ExecStartPre you can also use ExecStartPost, it depends on your situation. The interface must be DOWN to change the mac address. It is also not a bad idea to use b8:27:eb as first three bytes if you are on a built-in RasPi device because that is the identifier for Raspberry Pi.

Ingo
  • 42,107
  • 20
  • 85
  • 197
  • I tried using MACAddress, it does not work. I think it is an issue with the driver, because I also can’t change the mac address with macchanger. – jake Dec 09 '18 at 14:37
  • @jake And on the command line it also doesn't work? sudo ip link set eth0 address b8:27:eb:06:e8:88 or any other available interface that is just DOWN. Check with ip addr. – Ingo Dec 09 '18 at 19:11
  • No, doesn't work. So I think the interface does not support it. But systemd doesn't seem to even try changing the mac address, as it does not give an ip address to the same device. – jake Dec 09 '18 at 19:26