Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

auto add usb network to bridge

87 views
Skip to first unread message

Petric Frank

unread,
Sep 25, 2023, 5:40:06 AM9/25/23
to
Hello,

a special problem. I have a debian (12) machine which has an onboard network
card. This machine acts as dhcp-server also.

Now i want to add a usb network device. But this is not always there. It is
plugged in when needed. And it should serve the same network as the onboard
one.

My idea was to create a bridge and attach the host network interface to it.
The problem now is how to get the usb network card attached to the bridge when
plugged in.

My /etc/network/interfaces reads like this:
------------------ cut --------------------
auto lo
iface lo inet loopback

# onloard device
iface ens18 inet manual

# usb device (not always there)
iface enx0 inet manual

auto br0
iface br0 inet static
address 10.10.10.1/24
bridge-ports ens18 enx0
bridge-stp off
bridge-fd 0
------------------ cut --------------------

This works as long the usb device is plugged in at boot time.

Connecting it later the usb network device appears but will not be attached to
the bridge.

Any hints ?

regards
Petric

Nicolas George

unread,
Sep 25, 2023, 6:00:07 AM9/25/23
to
Petric Frank (12023-09-25):
> a special problem. I have a debian (12) machine which has an onboard network
> card. This machine acts as dhcp-server also.
>
> Now i want to add a usb network device. But this is not always there. It is
> plugged in when needed. And it should serve the same network as the onboard
> one.
>
> My idea was to create a bridge and attach the host network interface to it.
> The problem now is how to get the usb network card attached to the bridge when
> plugged in.

Hi.

I used to do just that to bridge my two wlan adapters (until a reboot
where the mt76x2u started to refuse to believe it was not in China and
to use the 5 GHz band; I switched to stand-alone mesh access points).
Here is my config:

auto wlanA
iface wlanA inet static
address 10.0.128.1
netmask 255.255.255.0
network 10.0.128.0
broadcast 10.0.128.255
bridge_ports none
post-up systemctl try-reload-or-restart isc-dhcp-server.service

iface wlan0 inet manual
post-up iw dev wlan0 set 4addr on || true
post-up ip link set dev wlan0 master wlanA
post-up systemctl start hos...@wlan0.service
pre-down systemctl stop hos...@wlan0.service

iface wlan1 inet manual
post-up iw dev wlan1 set 4addr on || true
post-up ip link set dev wlan1 master wlanA
post-up systemctl start hos...@wlan1.service
pre-down systemctl stop hos...@wlan1.service

I think the lines that will be of use for you are “bridge_ports none”
and “post-up ip link set dev wlan* master”.

Regards,

--
Nicolas George

Reco

unread,
Sep 25, 2023, 6:10:06 AM9/25/23
to
Hi.

On Mon, Sep 25, 2023 at 11:35:50AM +0200, Petric Frank wrote:
> My /etc/network/interfaces reads like this:
> ------------------ cut --------------------
> auto lo
> iface lo inet loopback
>
> # onloard device
> iface ens18 inet manual
>
> # usb device (not always there)
> iface enx0 inet manual
>
> auto br0
> iface br0 inet static
> address 10.10.10.1/24
> bridge-ports ens18 enx0
> bridge-stp off
> bridge-fd 0
> ------------------ cut --------------------
>
> This works as long the usb device is plugged in at boot time.
>
> Connecting it later the usb network device appears but will not be attached to the bridge.

You have to do it differently, like this:

auto lo
iface lo inet loopback

# onloard device
iface ens18 inet manual

# usb device (not always there)
allow-hotplug enx0
iface enx0 inet manual
up /sbin/ip link set $IFACE master br0

auto br0
iface br0 inet static
address 10.10.10.1/24
bridge-ports ens18
bridge-stp off
bridge-fd 0

What that does is forces udev to execute "ifup enx0" on USB device
detection, which in turn causes the network interface to attach to br0.

Reco

Petric Frank

unread,
Sep 25, 2023, 7:00:06 AM9/25/23
to
Hello Reco,

the "allow-hotplug ..." and "up /sbin/ip ..." what what i was missing. Works
like a charm.

Thanks for your and others support.

regards
Petric
0 new messages