Skip to content

Instantly share code, notes, and snippets.

@expipiplus1
Created September 27, 2017 08:45
Show Gist options
  • Save expipiplus1/5bfe42f63721e870f12b6f73ec3f2e7e to your computer and use it in GitHub Desktop.
Save expipiplus1/5bfe42f63721e870f12b6f73ec3f2e7e to your computer and use it in GitHub Desktop.
systemd.services.eth0-mac-change =
let iname = "eth0";
macaddress = "aa:aa:aa:aa:aa:aa";
subsystemdevice = interface:
"sys-subsystem-net-devices-${lib.escapesystemdpath interface}.device";
devicedependency = if config.boot.iscontainer
then []
else [ (subsystemdevice i.name) ];
in {
description = "mac configuration of ${iname}";
wantedby = [ "network-interfaces.target" ];
before = [ "network-interfaces.target" ];
after = [ "network-link-${iname}" ];
path = [ pkgs.iproute pkgs.nettools ];
serviceconfig = {
type = "oneshot";
remainafterexit = true;
};
script =
''
echo "configuring link..."
echo "setting mac address to ${macaddress}..."
ifconfig down ${iname}
ip link set "${iname}" address "${macaddress}"
ifconfig up ${iname}
'';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment