HowToSetUpUsbNetworkingDebian

This is rewrite of the "HOWTO :Set up USB networking" document special for Debian distribution (sarge and etch so far)

HOWTO: Set up USB networking with Debian

Introduction

This document describes how you can set up USB networking between your host machine with Debian and your device with a Debian-like distribution. Following this document you can easily transfer data between these two entities and log on as root to the device.

First, you need to follow the HowDoiBecomeRoot document. The commands executed on the device need to be done as root.

Setting up your environment and device

You need to take these steps:

1 .#1 Disconnect the device from the USB connection 1 .#2 Make sure that the PC's kernel has usbnet Support.

With “lsmod | grep usbnet” you should find that the module was loaded (if you don’t have it compiled in kernel on desktop).

~# lsmod | grep usbnet
usbnet                 18888  0

1 .#3 Then add networking information at the end of /etc/network/interfaces on the PC:

allow-hotplug usb0

mapping hotplug
        script grep
        map usb0

iface usb0 inet static
       address 192.168.2.1
       netmask 255.255.255.0
       broadcast 192.168.2.255
       up iptables -I INPUT 1 -s 192.168.2.2 -j ACCEPT

1 .#4 Check if module g_ether is loaded on the device. In case it is not loaded, check if it is included in the modules directory of your shipped version of Nokia 770 and load it, so you will not need to flash a development root filesystem really. This sets the device to networking-mode, it will no longer work as a mass-storage device. See the last section on how to get it back.

Execute the following command on the device:

lsmod | grep g_ether

If output is empty then You need to load g_ether.ko:

insmod /mnt/initfs/lib/modules/`uname -r`/g_ether.ko

1 .#5 Now you need to configure the network on the device. Add the following lines to /etc/network/interfaces on the 770 and comment out or delete the existing usb0-entry:

iface usb0 inet static
       address 192.168.2.2
       netmask 255.255.255.0
       broadcast 192.168.2.255
       up route add default gw 192.168.2.1

1 .#6 Connect device to usb

1 .#7 If you want comfortable browsing, you need a name-server. I recommend setting up pdnsd on your PC and entering the following line at the end of /etc/resolv.conf on the 770:

nameserver 192.168.2.1

1 .#8 Final step: fire up the interfaces! Do the following command on the PC and the 770:

/sbin/ifup usb0

Testing the connection

To test that the USB connection between your host and device works you can follow these simple steps.

2 . Attach the USB cable to the device 2 . The device should now be connected. You can check this with ifconfig, where you should see the device "usb0" in the list 2 . Now you can try to ping the device over the network with the address 192.168.2.15 2 . If the ping answers, log into the device as root. The root password is rootme

 ssh root@192.168.2.15 

Setting the device back into mass-storage-mode

unload the g_ether module:

   rmmod g_ether

and replug the USB cable.

Sharing internet

It should be possible to share internet over USB, either from desktop to Nokia, or reversed.

Host as a gateway

If your host has no firewalling rules, you can set the gateway rules by modifying /etc/interfaces file.

iface usb0 inet static
        address 192.168.2.1
        netmask 255.255.255.0
        up echo 1 > /proc/sys/net/ipv4/ip_forward
        up iptables -P FORWARD ACCEPT
        up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.2.0/24
        down echo 0 > /proc/sys/net/ipv4/ip_forward
        down iptables -t nat -F POSTROUTING

Else add the necessary MASQUERADE rules to normal firewall rules.

If you get the following error:

iptables v1.2.11: can't initialize iptables table `NAT': Table does not exist (do you need to insmod?) Perhaps iptables or your kernel needs to be upgraded.

You need verify that your kernel has the relevant iptables modules included, and hotplug or udev is set up properly on your computer.

Nokia as a gateway

Frst you need to build and install nat kernel modules. Follow HowTo KernelCompilation instructions to build kernel, but just before building kernel add more modules in, and copy the modules over to the device, instead of flashing the kernel.

# echo 1 > /proc/sys/net/ipv4/ip_forward
# iptables -P FORWARD ACCEPT
# iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.2.0/24

Could someone just post a link to that module here so that people without a Scratchbox can use this as well?

OS2006 maemo-dm

If you have OS2006 on your 770, simpler than doing insmod and rmmod manually is to apt-get install maemo-dm then reboot and click the pretty box on the toolbar to switch to/from usbmode.