[Networkmanager] nic sub-interface

Robin Becker robin at reportlab.com
Tue May 9 12:39:05 UTC 2023


On 08/05/2023 18:26, Chris Adams wrote:
> Once upon a time, Robin Becker <robin at reportlab.com> said:
>> On 08/05/2023 15:04, Thomas Haller wrote:
>>> Why? After moving the port to the bridge, the "new" configuration is
>>> supposed to work. Just add the IP addresses (or `ipv4.method=auto`) on
>>> the bridge profile, instead of the eno1 profile from before.
>> .......
>> I am almost certain this is right, but perhaps my router is interfering.
> 
> The way I do it, if I'm converting enp3s0 to br0, copying the IPv4/IPv6
> options from the base:
> 
>     nmcli con add con-name br0 ifname br0 type bridge stp 0 $(nmcli -t con show enp3s0 | grep '^ipv[46]\..*:.' | sed 's/:/ /') autoconnect 0
> 
>     nmcli con add con-name enp3s0-br0 ifname enp3s0 type bridge-slave master br0 autoconnect 0
> 
>     nmcli con down enp3s0; nmcli con up br0; nmcli con up enp3s0-br0
> 
>     nmcli con mod br0 autoconnect 1
>     nmcli con mod enp3s0-br0 autoconnect 1
>     nmcli con mod enp3s0 autoconnect 0
> 

OK I think most of my problems are resolved. I think the main issue was that I need to get a standard mac-address for 
the bridge so that my router can assign an ip address and also put the mac into the allowed (non-blocked) device list.

Following Chris Adams' approach I wrote a script to create the bridge setup and also to tear it down. I suppose the tear 
down ought also to check for more slaves. To make things less ambiguous I assumed that the connection id and device name 
were the same. To get the base value across I had to extend his sed to ignore -- values and remove (none) (default) etc etc.

I'm still not sure if I could have used the base mac address for the bridge. Thanks for the assistance.



#!/bin/bash
PROG="$(basename $0)"
case "$dryrun" in
   (on|yes|1|true) action="echo ";;
   (off|no|0|false|"") action="sudo";;
   (*) echo "!!!!! $PROG: bad dryrun value '$dryrun'" 1>&2 && exit -1;;
esac
#base device should match dev and con
BASE=${BASE:-eno1}
#bridge
BR=${BR:-br0}
BASEVALUES="$(nmcli con show "$BASE" 2>/dev/null)"
[ "$?" != 0 ] && echo "!!!!! $PROG: profile '$BASE' not found" && exit -4
case "${1:-create}" in
   (create)
     BRVALUES="$(nmcli con show "$BR" 2>/dev/null)"
     [ "$?" = 0 ] && echo "!!!!! $PROG: profile '$BR' already exists" && exit -5
     BASEVALUES="$(echo "$BASEVALUES" | grep '^ipv[46]\..*:.\|connection\.autoconnect-' | sed '/--/d;s/:/ /;s/ 
(\(default\|none\|unspec\|disabled\))//') autoconnect 0"
     $action nmcli con add con-name "$BR" ifname "$BR" type bridge stp 0 ${BASEVALUES}
     $action nmcli con mod "$BR" ethernet.cloned-mac-address AA:BB:CC:11:22:33 #fix the mac addr for router
     $action nmcli con add con-name "$BASE"-"$BR" ifname "$BASE" type bridge-slave master "$BR" autoconnect 0
     $action nmcli con down "$BASE"
     $action nmcli con mod "$BASE" autoconnect 0
     $action nmcli con up "$BR"
     $action nmcli con up "$BASE"-"$BR"
     $action nmcli con mod "$BR" autoconnect 1
     $action nmcli con mod "$BASE"-"$BR" autoconnect 1
     ;;
   (delete)
     BRVALUES="$(nmcli con show "$BASE-$BR" 2>/dev/null)"
     if [ "$?" != 0 ]; then
       echo "!!!!! $PROG: profile '$BASE-$BR' not found"
     else
       $action nmcli con down "$BASE"-"$BR"
       $action nmcli con delete "$BASE"-"$BR"
       echo "+++++ $PROG: profile '$BASE-$BR' deleted"
     fi
     BRVALUES="$(nmcli con show "$BR" 2>/dev/null)"
     if [ "$?" != 0 ]; then
       echo "!!!!! $PROG: profile '$BR' not found"
     else
       echo "+++++ $PROG: profile '$BR' deleted"
       $action nmcli con down "$BR"
       $action nmcli con delete "$BR"
     fi
     $action nmcli con mod "$BASE" autoconnect 1
     $action nmcli con up "$BASE"
     ;;
   (*) echo "!!!!! $PROG: unknown action '$1' use $PROG create|delete" && exit -2;;
esac

-- 
Robin Becker



More information about the Networkmanager mailing list