How to merge usb0 and usb1 interfaces into one network

forwardinglocal-area-networkusb

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?

Best Answer

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. :-)

Related Topic