Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs

Dashboard
Notifications
Mark all as read
Q&A

Access host device which bridges a connected device through same eth interface

+2
−0

I got 2 small computers running Linux. One acts as ethernet gadget, connected via USB to the other, the host.

I set up a bridge, like so:

ip link add name br0 type bridge
ip link set dev br0 up
ip link set dev eth0 master br0
ip link set dev usb0 master br0

On the gadget, its usb0 interface has 2 IP addresses: the one in the 169.... net that the host also has on its usb0, which I consider the "internal" connection/subnet between the two computers - and the second IP on the gadget is one in the "outside" subnet, which the bridging host is connected to with its eth0 interface.

This almost works. Except, when I run the script that sets up the bridge, I cannot connect to the host anymore, e.g. SSH into it with its eth0's own IP address.

Edit: What's weird is that establishing SSH connections to the host eth0's own IP still works for a while (e.g. a few minutes) after setting up the bridge, but ceases to work then.

I found something here, indicating that, if eth0 has a bridge to something else, it's not supposed to have an own IP address. The text suggests to add an address to the bridge:

ip addr flush dev eth0
ip addr add 192.168.128.5/24 dev br0
ip link set br0 up

That didn't help, though.

The goal is to be able to access both from the outside world (a local network with a bunch more computers), with all thinkable protocols: the host device, as well as the gadget, and bridging seemed like the way.

How is this done correctly?

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+0
−0

It seems that what the linked article says is usually correct, about the interfaces which are part of the bridge not being supposed to have IPs themselves. At least in the wanted subnet, I guess.

This seems a bit special here. I can't get the USB gadget stuff to work, i.e. any traffic between gadget and host, unless I assign the usb0 interfaces on both, gadget and host, an address in the 169.254.. net (or rather, let it auto assign that). So what I now do is, let the ethernet gadget stuff self-assign such addresses as it may, but assign no further (actually targeted subnet) address to usb0 nor eth0 on the host - only the bridge that connectes those two has such an address. On the gadget, the usb0 does get an additional IP which lies in the targeted ("intranet") subnet, though - as that's what's being bridged to the outside, on the host. That works.

I have found no reference that states: that, and why, interfaces involved in a USB ethernet gadget connection always need an IP (let alone in a special subnet). So this, unfortunately, is not quite a canonical answer. All I can say is: "this works for me".

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!