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
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
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.
macchanger
.
– jake
Dec 09 '18 at 14:37
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
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
Interface
instead ofName
. 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