On 05/19/2013 03:42 PM, Pavel Simerda wrote:
----- Original Message -----
From: "Alexei Colin" <[email protected]>
To: [email protected]
Sent: Sunday, May 19, 2013 5:32:03 AM
Subject: Select wired connection by router mac address?

Hello,

Is it possible to configure NM to select among automatically connectable
wired connections based on router mac address? Use case: automatically
connect at home and at work to the correct connection.
Hello,

Short answer: No.

Long answer: At the time of connection selection, this information is not known 
to NetworkManager. It would be possible with some magic to gather broadcasted 
information or even perform active checks based on e.g ARP/NDP. Then you could 
match to more than just a MAC address. Also it would be theoretically possible 
to transition from one connection configuration to another and then you could 
even use information from the DHCP exchange. I don't think anyone is working on 
this, even though it would be interesting and very practical.


There may be another way, use a dispatcher script in /etc/NetworkManager/dispatcher.d. Works if both networks use DHCP. Something like:

#!/bin/sh
# Script to dispatch NetworkManager events
#
# Runs ifupdown scripts when NetworkManager fiddles with interfaces.
# See NetworkManager(8) for further documentation of the dispatcher events.

# For debug
exec >/var/log/somename.log
exec 2>&1
set -x

MOUNTPOINTS="/some /mount /points"

if [ -z "$1" ]; then
    echo "$0: called with no interface" 1>&2
    exit 1;
fi

# Run the right scripts
case "$2" in
    up)
    NETMASK="<your-home-network>/<netmask>"
        if [ -n "`/sbin/ip -o addr show $IF to $NETMASK`" ]; then
        for mp in $MOUNTPOINTS; do
        if ! mount | grep -q " on $mp "; then
            mount $mp
        fi
        done
        ip ro add <some-target> via <some-router>
    fi
    ;;
    down)
    ip ro del <some-target> via <some-router>
    for mp in $MOUNTPOINTS; do
        if mount | grep -q " on $mp "; then
        umount -l $mp
        fi
    done
    ;;
    hostname)
    exit 0
    ;;
    hostname|dhcp4-change|dhcp6-change|vpn-up|vpn-down)
        # Do nothing
    ;;
    *)
    echo "$0: called with unknown action \`$2'" 1>&2
    exit 1
    ;;
esac


_______________________________________________
networkmanager-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to