USB Networking troubles

Andrew C. Dingman andrew+openmoko at dingman.org
Fri Aug 8 14:40:53 CEST 2008


On Fri, 2008-08-08 at 06:32 -0400, michael cole wrote:
> First thanks to all for replying.
> 
> These changes worked.

Glad it helped. I hope the IP routing mini-lecture made clear *why* :)

> So on my Freerunner /etc/network/interfaces includes:
> 
> # Ethernet/RNDIS gadget (g_ether)
> # ... or on host side, usbnet and random hwaddr
> auto usb0
> iface usb0 inet static
> 	address 192.168.2.202
> 	netmask 255.255.255.0
> 	network 192.168.2.0
> 	gateway 192.168.2.200
> # orig:
> #	up echo nameserver 192.168.0.200 >/etc/resolv.conf
> # using home (nimiq.net)
> 	up echo nameserver 207.235.125.4 >/etc/resolv.conf
> 
> on the desktop  /etc/network/interfaces includes:
> allow-hotplug usb0
> iface usb0 inet static
>         address 192.168.2.200
>         netmask 255.255.255.192
>         post-up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.2.192/26
>         post-up echo 1 > /proc/sys/net/ipv4/ip_forward
>         post-up iptables -P FORWARD ACCEPT
>         pre-down iptables -D POSTROUTING -t nat -j MASQUERADE -s
> 192.168.2.192/26

Almost right, and in fact this configuration won't break in practice
because you can't plug additional devices into your USB network.
However, the FreeRunner and the desktop really *should* agree about the
netmask. You have the FreeRunner thinking its local network includes 256
addresses (192.168.2.0-255), and the desktop thinking that the network
it and the FreeRunner live in includes only 64 (192.168.2.192-255). If
you choose to fix this on the desktop by using the 255.255.255.0
netmask, you'll also want to fix the masquerade rule to specify
192.168.2.192/24, as the /n part indicates a netmask with binary 1 in
the n most significant bits. (255.255.255.0 == binary IP 11111111
11111111 11111111 00000000. 255.255.255.192 == binary 11111111 11111111
11111111 11000000)

If you want to play with this stuff a bit more, you might be interested
in a tool called 'gip' that you can install on your desktop with
'apt-get install gip'. It lets you enter IPs and netmasks in any of the
normal forms and shows you the resulting network sizes and binary,
hexadecimal, and decimal representations of the results.
-- 





More information about the support mailing list