Re: Select wired connection by router mac address?

On 05/19/2013 03:42 PM, Pavel Simerda wrote:
----- Original Message -----
From: "Alexei Colin" <alexei alexeicolin com>
To: networkmanager-list gnome org
Sent: Sunday, May 19, 2013 5:32:03 AM
Subject: Select wired connection by router mac address?


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.

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:

# 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;

# Run the right scripts
case "$2" in
        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
        ip ro add <some-target> via <some-router>
    ip ro del <some-target> via <some-router>
    for mp in $MOUNTPOINTS; do
        if mount | grep -q " on $mp "; then
        umount -l $mp
    exit 0
        # Do nothing
    echo "$0: called with unknown action \`$2'" 1>&2
    exit 1

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]