Created
September 27, 2017 08:45
-
-
Save expipiplus1/5bfe42f63721e870f12b6f73ec3f2e7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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