USB Networking
This document describes how to create an USB Networking between your mobile device and your host machine.
Note: You MUST set up your mobile device first before setting up your host machine, or it won't work!
It is due to the host machine, that only starts the usb interface if the other peer has also its interface started.
Setting up your mobile device
Inside Mamona do:
sudo apt-get install usbnet
This package will add a script in your system that will be ran at the boot time, but you can also run it manually:
sudo /etc/init.d/usbnet start
Setting up your host machine
Note: Here we are considering that your host machine is a debian like distribution.
First make sure you have your kernel compiled with usbnet support.
If it's compiled as a kernel module check if it's already loaded:
sudo lsmod | grep usbnet
If it's not loaded do:
sudo modprobe usbnet
or
sudo insmod /lib/modules/`uname -r`/kernel/drivers/net/usb/usbnet.ko
Once you have usbnet support loaded let's set up your network interface inserting the following lines in your /etc/network/interfaces file:
Note: If you want your host machine configured as a gateway, go to the Gateway section.
allow-hotplug usb0
mapping hotplug
script grep
map usb0
iface usb0 inet static
address 10.0.1.11
netmask 255.255.255.0
broadcast 10.0.1.255
up iptables -I INPUT 1 -s 10.0.1.10 -j ACCEPT
Now is time to start your usb interface:
sudo ifup usb0
Note: The interface should be automatically started up next time, if NOT then you should add a rule to udev. Copy 99-usbnet.rules to /etc/udev/rules.d to solve the problem.
Testing
Let's test it:
ping 10.0.1.10
Another good option to test it is to install the ssh daemon and try to access remotely your mobile device.
Gateway
Insert the following lines in your /etc/network/interfaces file to have your host machine configured as a gateway:
iface usb0 inet static
address 10.0.1.11
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 10.0.1.0/24
down echo 0 > /proc/sys/net/ipv4/ip_forward
down iptables -t nat -F POSTROUTING
Attachments
- 99-usbnet.rules (280 bytes) - added by alecrim 3 months ago.
