How to enable DHCP on USB gadget

By | March 26, 2012

I have spent a couple of days scratching my head while trying to configure USB network gadget adapter. The platform is OpenEmbedded Linux on AT91, connected to a Windows 7 PC. Here we go:

The first small problem was that the network connection shows up as ‘cable disconnected’ in Windows. It is solved by putting auto usb0 to /etc/network/interfaces

Next, configuring DHCP server for automatic IP address. In my setup, I have a fixed IP address for the USB network connection in the Linux box. The embedded DHCP server (dnsmasq) assigns an address in the same subnet to the PC connected via USB.

In /etc/dnsmasq.conf (or recipes/dnsmasq/files/dnsmasq.conf), put the interface to listen to and the IP address range in the appropriate places:

interface=usb0
dhcp-range=192.168.200.50,192.168.200.150,12h

It seems that there is an issue in dnsmasq – when the USB cable is plugged in after dnsmasq is started, IP address is still not assigned. I solved it (at least temporarily) by restarting dnsmasq in /etc/network/interfaces:

auto usb0
iface usb0 inet static
        address 192.168.200.200
        netmask 255.255.255.0
        network 192.168.0.0
# enable if the host is a gateway
#        gateway 192.168.200.200
        post-up /etc/init.d/dnsmasq restart

Leave a Reply

Your email address will not be published.