Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

networkmanager service: support changing the mac-address #23464

Merged
merged 4 commits into from Mar 7, 2017

Conversation

TomSmeets
Copy link
Contributor

Motivation for this change

Setting the MAC-address with networking.interfaces.wlan0.macAddress does not work when using networking.networkmanager.

Things done

This commit introduces these options: networking.networkmanager.wifi.macAddress
and networking.networkmanager.ethernet.macAddress

Which can be set to these possible values

  • "XX:XX:XX:XX:XX:XX": set the MAC address of the interface.
  • "permanent": use the permanent MAC address of the device.
  • "preserve": don’t change the MAC address of the device upon activation.
  • "random": generate a randomized value upon each connect.
  • "stable": generate a stable, hashed MAC address.

See https://blogs.gnome.org/thaller/2016/08/26/mac-address-spoofing-in-networkmanager-1-4-0/ for more information

Notes

The networkmanager service has to be restarted after changing these settings.
This can be done by calling:

systemctl restart network-manager.service

Is it possible to do this automatically?


  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Set `networking.networkmanager.wifi.macAddress` or `networking.networkmanager.ethernet.macAddress`
to one of these values to change your macAddress.

* "XX:XX:XX:XX:XX:XX": set the MAC address of the interface.
* "permanent": use the permanent MAC address of the device.
* "preserve": don’t change the MAC address of the device upon activation.
* "random": generate a randomized value upon each connect.
* "stable": generate a stable, hashed MAC address.

See https://blogs.gnome.org/thaller/2016/08/26/mac-address-spoofing-in-networkmanager-1-4-0/ for more information
@mention-bot
Copy link

@TomSmeets, thanks for your PR! By analyzing the history of the files in this pull request, we identified @rickynils, @domenkozar and @urkud to be potential reviewers.

@joachifm
Copy link
Contributor

joachifm commented Mar 3, 2017

If changing the config affects the service definition, restartIfChanged suffices (on by default); otherwise you can add arbitrary derivations to restartTriggers (if you're generating a config file, for example, it'd make sense to add it to trigger a restart when the config changes).

@@ -140,6 +144,34 @@ in {
'';
};

ethernet.macAddress = mkOption {
type = types.nullOr (types.either types.str (types.enum ["permanent" "preserve" "random" "stable"]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does null mean here? Is it different from "preserve"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this so that the networkmanager could choose the default value (if none has been set).

But after checking the blog-post, it might be better to use "preserve"

Update-2017-01-25: with 1.6 release and newer, the default value changed from “permanent” to “preserve” [commit],[bug].

By setting the default to "preserve" might acctually fix the issue with setting networking.interfaces.wlan0.macAddress while the networkmanger is used.

I will change the default to "preserve"

};

wifi.macAddress = mkOption {
type = types.nullOr (types.either types.str (types.enum ["permanent" "preserve" "random" "stable"]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the type is exactly the same as for the above option; perhaps it could be factored out and re-used.

@joachifm joachifm merged commit 9a7bad2 into NixOS:master Mar 7, 2017
@joachifm
Copy link
Contributor

joachifm commented Mar 7, 2017

Thank you

@TomSmeets TomSmeets deleted the nm-chmac branch March 12, 2017 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants