1

I have a set-up with three devices, all running Ubuntu 14.04. The set up looks as follows:

Network set-up with one host and two devices.

What I would like to have is a configuration in which both devices can connect to the internet but can also connect to each other. And ideally, the host PC should have the same IP when connected to from either device. I have tried two possible configurations, but both failed.

1: usb0 and usb1 use the same IP and subnet

host

iface usb0 inet static
    address 10.0.1.1
    netmask 255.255.255.0
    up route add 10.0.1.1 netmask 255.255.255.0

iface usb1 inet static
    address 10.0.1.1
    netmask 255.255.255.0
    up route add 10.0.1.1 netmask 255.255.255.0

device 0

iface usb0 inet static
    address 10.0.1.2
    netmask 255.255.255.0
    route add default gw 10.0.1.1

device 1

auto usb0
iface usb0 inet static
    address 10.0.1.3
    netmask 255.255.255.0
    route add default gw 10.0.1.1

! problem !

Only device 0 gets connected. This one can be pinged, and it can connect to the internet but device 1 is completely out of the game. It therefore also has no internet connection.

2: usb0 and usb1 have a different IP address

host

iface usb0 inet static
    address 10.0.1.1
    netmask 255.255.255.0
    up route add 10.0.1.1 netmask 255.255.255.0

iface usb1 inet static
    address 10.0.2.1
    netmask 255.255.255.0
    up route add 10.0.2.1 netmask 255.255.255.0

device 0

iface usb0 inet static
    address 10.0.1.2
    netmask 255.255.255.0
    route add default gw 10.0.1.1

device 1

auto usb0
iface usb0 inet static
    address 10.0.2.2
    netmask 255.255.255.0
    route add default gw 10.0.2.1

! problem !

I am not able to ping 10.0.1.1 from device number 1.

Question

How do I connect the two usb interfaces so that it forms a bigger local network in which ideally every machine has one IP address, is connected to the internet and is able to access every other machine through SSH?

  • Why are you using USB network interfaces? – EEAA Sep 28 '15 at 2:31
  • Because the devices are connected by a USB cable. – hhhhhhhhh Sep 28 '15 at 3:23
  • Sounds like you need bonding/teaming. Assuming the USB-ness of the interfaces won't get in the way. – womble Sep 28 '15 at 4:36
3

What you need is to configure bridging. What bridging will do, is basically tie together a bunch of interfaces, and then letting the computer running the bridge act as a switch. The IP address is configured on the bridge interface itself, rather than on the constituent interfaces.

There are basically two ways you can do this, either you set up a bridge with the two USB interfaces, and then use iptables and presumably some kind of NAT to route the machines to the Internet, or you can just stick both USB interfaces as well as the physical interface in a single bridge. That way, you would let your USB interfaces connect directly to your LAN and get internet access that way.

It's up to you to choose which one makes more sense for your application.

The configuration (/etc/network/interfaces) for the setup where the usb network interfaces are bridged to your main network might look something like this, assuming your main network interface is called eth0.

iface eth0 inet manual
iface usb0 inet manual
iface usb1 inet manual

auto br0
iface br0 inet dhcp
  bridge_ports eth0 usb0 usb1

More details may be found in the Ubuntu community help wiki.

In this setup, your USB network devices would either get IP addresses from the existing DHCP server in your network, or would be configured with static IP addresses in your local LAN. Also your PC would get the IP using DHCP. Make sure that your USB-connected devices don't run a DHCP server if you do this or you might make other users of your network cross. :-)

| improve this answer | |
  • Do the interfaces need to be on the same subnet? I tried it multiple ways, but without any luck. I think the best approach is to have them on a different subnet, because then at least I know for sure that both can be pinged from the host. A more comfortable starting point. – hhhhhhhhh Sep 30 '15 at 5:47
  • As I wrote in the post above: "The IP address is configured on the bridge interface itself, rather than on the constituent interfaces." You do not put IP addresses on the physical interfaces themselves, just on the bridge interface that contains the physical interfaces. – Per von Zweigbergk Sep 30 '15 at 6:07
  • I interpreted that the wrong way. I have it up and running now. My misunderstanding was that a bridge acts as a link between the two configured usb interfaces. But it actually ís the configuration for the USB interfaces as well. Therefore the USB interfaces should be down, and I was blind to that fact. Thank you for the response. – hhhhhhhhh Sep 30 '15 at 7:22
0

In the end it was configured as follows:

host

/etc/network/interfaces

auto br0
iface br0 inet static 
    address 10.0.1.1
    netmask 255.255.255.0
    bridge_ports usb0 usb1
    pre-up ip addr flush dev usb1
    pre-up ip addr flush dev usb0

/etc/rc.local

sleep(15)
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward > /dev/null
iptables -P FORWARD ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE -s 10.0.1.0/24

device 0

/etc/network/interfaces

auto usb0
iface usb0 inet static
    address 10.0.1.2
    netmask 255.255.255.0
    dns-nameserver 8.8.8.8
    up route add default gw 10.0.1.1

device 1

/etc/network/interfaces

auto usb0
iface usb0 inet static
    address 10.0.1.3
    netmask 255.255.255.0
    dns-nameserver 8.8.8.8
    up route add default gw 10.0.1.1
| improve this answer | |
  • That config looks really broken. You've got overlapping subnets, the netmask on br0 is incorrect, and there's nothing here showing how the bridge config itself is set up. I think you'll find that it's gonna break if you reboot. – Per von Zweigbergk Sep 30 '15 at 11:42
  • The subnet issue was a typo. I updated the configurations, please correct me if it looks erroneous or if I am using bad practices; I'm completely green when it comes to setting up networks. The only problem I still observe is that executing the internet forwarding commands from rc.local is not working properly. It used to when I was using separate usb interfaces (without the sleep() ) and it works when I execute them straight from terminal after logging in... – hhhhhhhhh Oct 1 '15 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.