Hi all, I am interested in automatically selecting an Ethernet connection profile based on the network to which I'm connected, probably identified by ARP probes. I noticed there has been some previous interest in this feature[1][2] along with TODO implementation notes.[3] Until/Unless it is implemented, I came up with a workaround. I'd appreciate any thoughts or feedback for issues I may have overlooked or whether it might be worth sending an MR to add it to nmcli-examples(7).
First, I created a high-priority connection profile from which detection can be done: nmcli connection add \ type ethernet \ con-name ethdetect \ connection.autoconnect-priority 100 \ connection.multi-connect=3 \ ipv4.method disabled \ ipv6.method disabled Then I created a dispatcher.d script to perform the detection and activate the detected connection profile: -8<---------------------------------------------------------------- #!/bin/sh if [ "$2" != up ] || [ "$CONNECTION_ID" != ethdetect ]; then exit 0 fi # Network detection using arping(8) # Probe for MAC 00:01:02:03:04:05 at address 192.168.1.1 if arping -q0 -I "$DEVICE_IFACE" -c1 -C1 -t 00:01:02:03:04:05 192.168.1.1; then # MAC/IP found. Activate an appropriate connection profile. exec nmcli connection up myconn1 ifname "$DEVICE_IFACE" fi # Network detection using guessnet(8) # Runs multiple tests concurrently then prints a matched name or default detected=$(guessnet -d mydefault "$DEVICE_IFACE" <<'GUESSNET_TESTS' # At home, look for a host with the given IP and MAC address home peer 192.168.1.1 00:01:02:03:04:05 # At the university, check for the presence of at least one # of the following hosts university peer 130.136.1.1 05:06:03:02:01:0A university peer 130.136.1.2 15:13:B3:A2:2F:CD GUESSNET_TESTS ) # Activate detected connection profile exec nmcli connection up "$detected" ifname "$DEFICE_IFACE" -8<---------------------------------------------------------------- After some brief testing, this appears to work well for my purposes. Thoughts? Problems? Worth adding to nmcli-examples(7)? Thanks for considering, Kevin P.S. I am not familiar enough with 802.1x to know whether it's possible to detect from the ethdetect connection state. If it can be done in a few lines, I'd be happy to add that to the example. [1]: https://mail.gnome.org/archives/networkmanager-list/2009-May/msg00084.html [2]: https://mail.gnome.org/archives/networkmanager-list/2013-May/msg00144.html [3]: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/1.28.0/TODO#L42 _______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list