HowTos/USB Networking Without Bridging

From OpenZaurus

This describes how to use the Zaurus's cradle or USB cable, in conjunction with a desktop or laptop running Linux, to connect your Zaurus to the network. Unlike HowTos/USB_Networking, this method uses IPv4 forwarding rather than interface bridging; if you have trouble getting bridging to work (as I did), you may have better luck with this method.

Contents

Prologue

This document makes a few assumptions about network topology, based on my home network (which is what I set up and tested it on): - master gateway (between LAN and WAN) is 192.168.1.1 -- this is "MG" - nameserver is 192.168.1.2 -- this is "NS" - the Zaurus will connect through a computer we will call the "Zaurus Gateway" (ZG)... - which is connected to the MG on eth0, with the IP 192.168.1.200

Also, note that this document does not really cover automating this process, in particular things like automatically bringing up/down interfaces when the Zaurus is attached/detached and so forth; each distro has its own ways of doing this and I'm still getting a handle on it myself.

I wrote this based on my experiences with a Fedora Core 5 box, but it should be broadly applicable to most if not all recent Linuxes.

On the Zaurus Gateway

Attach the Zaurus to the ZG

Simple enough; plug it in and see what happens. If all goes well you should see something like "kernel: usb0: register 'zaurus' at usb-XXXX:XX:XX.X-X, Sharp Zaurus XXXXXXX, XX:XX:XX:XX:XX:XX" in your syslog, followed by some information about usb0 Ethernet drivers and the like.

In 3.5.4.2-rc2 I needed to load g_ether driver (modprobe g_ether) on my poodle (zaurus sl-5600).

Configure the ZG's interfaces

First, bring up the USB network interface, it if wasn't brought up automatically:

# ifup usb0

And give it an IP appropriate to a gateway

# ifconfig usb0 192.168.2.1

Configure the ZG's route and IP forwarding information

Set up a route to the Zaurus:

# route add -net 192.168.2.0 netmask 255.255.255.0 dev usb0

Your routing table should now look something like this:

Destination    Gateway        Genmask        Flags Metric Ref   Use Iface
192.168.2.0    *              255.255.255.0  U     0      0       0 usb0
192.168.1.0    *              255.255.255.0  U     0      0       0 eth0
default        192.168.1.1    0.0.0.0        UG    0      0       0 eth0

Next, enable IPv4 forwarding, or the Zaurus will be able to talk to the ZG, but nothing else:

# sysctl -w net.ipv4.ip_forward=1

or

# echo 1 > /proc/sys/net/ipv4/ip_forward

If you're running an iptables firewall, you'll need to either disable it:

# /etc/init.d/iptables stop

Or add a forwarding rule to it for the Zaurus. On Fedora 5 this code goes in /etc/sysconfig/iptables at the top; I don't know where other distros keep it, but it shouldn't be hard to find.

-t nat -A POSTROUTING -s 192.168.2.100 -j MASQUERADE

and reload iptables to update it:

# /etc/init.d/iptables restart

Debian users may add the above to /etc/network/interfaces (on the host machine, not the Zaurus) by an 'up' statement in the revelant stanza:

up iptables -t nat -A POSTROUTING -s 192.168.2.100 -j MASQUERADE

On the Zaurus

Configure the Zaurus's network interface

You can do this with either the graphical configurator, or by editing /etc/network/interfaces directly. Make sure you edit the right interface; on 2.4 kernel machines using the Sharp Lineo gadget drivers it is called "usbd0", on 2.6 kernel machines using the stock gadget drivers it is "usb0". It should come up automatically when you plug the Zaurus in, so if all else fails, # ifconfig and look for things that aren't infrared, WLAN or loopback. The settings from my /etc/network/interfaces are reproduced below; it should be fairly obvious how to adapt them for other interfaces or a graphical configurator :P

iface usbd0 net static
    address 192.168.2.100
    netmask 255.255.255.0
    network 192.168.2.0
    gateway 192.168.2.1

Restart the network interface:

# ifdown usbd0
# ifup usbd0

Double-check the Zaurus's route; it should look something like this:

Destination    Gateway        Genmask        Flags Metric Ref   Use Iface
192.168.2.0    *              255.255.255.0  U     0      0       0 usbd0
default        192.168.2.1    0.0.0.0        UG    0      0       0 usbd0

Configure the Zaurus's resolver

This is simple; just

# rm /etc/resolv.conf

(it's a broken symlink to a temporary config file by default??) and replace it with your actual nameserver:

# echo "nameserver 192.168.1.2" > /etc/resolv.conf

Test it

If all has gone well, you should now be able to ping 192.168.2.100 from the ZG and get a response from the Zaurus, and ping 192.168.2.1 from the Zaurus and get a response from the ZG. This might also be a good time to SSH into the Zaurus and play around with it. If all of this works, there's just one last step needed to provide the Zaurus with its link to the greater internet.

On the Master Gateway

Configure the Gateway's route

We need to teach your master gateway how to route packets to the Zaurus, since it's not directly attached. Add the following route:

Destination    Gateway          Netmask        Iface
192.168.2.0    192.168.1.200    255.255.255.0  LAN

I can't give precise instructions on how to do this, as it varies by gateway; on Linux systems (including things like HyperWRT-based Linksys routers) you can:

# route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.200 dev eth0

(on a WRT54G, it's br0, not eth0; fill in interface names as appropriate to your system)

Test it again

Now you should be able to access the internet from your Zaurus. Try pinging the master gateway from it, or www.openzaurus.org. If all went well, you should see packets flowing freely between the Zaurus and the internet at large.

See Also

route(8), ifconfig(8), iptables(8)