Linux – DHCP for USB virtual ethernet interface

dhcplinuxnetworking

I'm attempting to connect my Arietta G25 Debian ARM board to my home network using DHCP (or failing that, a static IP in the correct subnet). I'm currently using the board over USB, which shows up as some kind of virtual Ethernet interface which is configured using a static 192.168.10.0/24 IP. I can access it (SSH) from the machine it's plugged into, but I want to be able to access the rest of my network on 192.168.1.0/24 and the internet from the board, as well as access the board from my home network.

The home network is on the 192.168.1.0/24 subnet.

Currently, I have two /etc/network/interfaces files:

Host config (Linux host box)

allow-hotplug usb0
iface usb0 inet static
    address 192.168.10.20
    netmask 255.255.255.0

Board config (Debian ARM board over USB)

auto usb0
iface usb0 inet static
    address 192.168.10.10
    netmask 255.255.255.0
    gateway 192.168.10.20

I've tried setting the board's IP to 192.168.1.90 but that made it unaccessible. Something to do with the gateway perhaps? I've also tried

iface usb0 inet dhcp

to no avail.

How can I get my USB-connected-with-virtual-ethernet-interface ARM board to have an IP address (DHCP or static) on the 192.168.1.0/24 subnet used by the rest of my network when plugged into a box over USB? I'd prefer to use DHCP. There is a DHCP server running on the router on 192.168.1.1.

Best Answer

Setting the board's IP to 192.168.1.90 will not work because routing will fail. If you run ip route on the host box, it will show that 192.168.1.0/24 is connected via your normal network connection to the rest of the LAN. It is trying to route packets out that interface and not usb0 as intended.

Two options:

  1. Use the Linux host as a router. This requires enabling forwarding and setting up NAT (MASQUERADING) with iptables (this is actually pretty simple)

  2. Create a bridge interface on your host box and add both of the physical interfaces to that bridge. This is basically like connecting them both to the same switch, but done in software. I will assume your network is connected to the host box on eth0:

    brctl addbr br0
    brctl addif br0 usb0
    brctl addif eth0
    

This should Just Work©. You may need to install the bridge-utils package. Since you're using a Debian-based distro, see here.

Related Question