2 ms·
IME the most reliable way to do this is with a udev rule. Here's my setup (Fedora, so YMMV). /etc/udev/rules.d/51-macchanger.sh: SUBSYSTEM=="net", ACTION=
by kyboren 12y ago
IME the most reliable way to do this is with a udev rule.
Here's my setup (Fedora, so YMMV).
/etc/udev/rules.d/51-macchanger.sh:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="iwlwifi", RUN+="/usr/local/bin/change-mac.sh wlp0s1"
/usr/local/bin/change-mac.sh:
#!/bin/bash
(
if [ "$#" != "1" ]
then
echo "mac changer script must be given iface name as argument: $@"
echo "Using default of wlp0s1 instead."
iface="wlp0s1"
else
iface=$1
fi
/usr/sbin/ifconfig $iface down
/bin/macchanger -r -b $iface #change to any random MAC address
/usr/sbin/ifconfig $iface up
) >/var/log/change-mac
Note that you would need to specify the correct interface name in the udev rule (or figure out a way to get it dynamically--I never bothered). This also only works for Intel WiFi cards that use the iwlwifi driver; other cards with different drivers need their udev rule changed appropriately.