Skip to content

Instantly share code, notes, and snippets.

@jdiamond
Last active November 15, 2016 21:32
Show Gist options
  • Save jdiamond/1b248f0fa4107a4fa9d57b7cb878bbfe to your computer and use it in GitHub Desktop.
Save jdiamond/1b248f0fa4107a4fa9d57b7cb878bbfe to your computer and use it in GitHub Desktop.
systemd OUI service

This unit file changes the OUI in the MAC addresses for enabled interfaces. It leaves the remaining bytes as is.

Copy [email protected] to /etc/systemd/system.

Enable it for each interface like this:

sudo systemctl enable oui@eth0
sudo systemctl enable oui@wlan0

Reboot then check your MAC addresses like this:

ifconfig | grep HWaddr

Tested with Raspbian Jessie (2016-09-23).

Most of the information I needed came from the Arch Wiki, but I had to play with the dependencies until it worked consistenly for both interfaces. (wlan0 would sometimes be broken after a reboot depending on the order in which the services ran.)

[Unit]
Description=Change OUI for %I
After=networking.service
Before=dhcpcd.service
[Service]
Type=oneshot
Environment="OUI=00:0c:59"
ExecStart=/bin/sh -c "ip link set dev %i address \"$OUI:$(ip link show %i | awk '/link\/ether/ {print substr($2, 10)}')\""
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment