refer: Original link
Tethering means sharing the Internet connection of an Internet-capable mobile phone with other devices. This sharing can be offered over a wireless LAN (Wi-Fi), or over Bluetooth, or by physical connection using a cable (Tethering).
Our focus in this article will be the USB tethering.
Your Android mobile phone can behave as an external network interface usbN, connected via the USB infrastructure. The usbN interface is in turn connected to the mobile phone LAN, providing dhcp server, DNS server, gateway and so on.
That’s how your mobile phone can provide an Internet connection to another device.
Android phones are already equipped to provide this functionality. Simply connect the USB cable and go to Settings -> Wireless settings -> Tethering -> Tethering USB.
What you need is some kernel and network configuration on the other side (e.g. your laptop).
Contents1
2
3
4
5
6
7
81 Kernel configuration
2 Tested Devices
3 Testing
4 Connecting
4.1 Manually
4.2 Permanent configuration
4.3 Checks
5 Advanced network settings
Kernel configuration
KERNEL .config 3.0.6-gentoo
1 | General setup ---> |
KERNEL .config 3.12.21-gentoo-r1
1 | Device Drivers ---> |
You can either build the options in the kernel or leave them as module.
Note. The RNDIS option seems to be needed in some situation only. See this thread to learn more.
Tested Devices
1 | Google Nexus One (Android 2.3.6 build GRK39F) |
Testing
1 | root #dmesg |
root #ifconfig -a
If you see usb0 (or whatever number you’ll get) you are all set.
Connecting
Since the mobile phone LAN changes its addresses, you need a DHCP client to configure the usbN device.
If you are on a laptop, you probably have a DHCP client. If not, emerge net-misc/dhcpcd.
root #emerge --ask net-misc/dhcpcd
Manually
Simply run dhcpcd after plug/mobile activation.
root #dhcpcd usb0
Permanent configuration
Edit your /etc/conf.d/net to have a permanent, automatic activation of the interface.
root #echo "config_usb0=\"dhcp\"" >> /etc/conf.d/net
Once plugged in and activated on the mobile phone side, the usb0 will be up and configured.
Checks
Run the usual checks to verify your connection.
1 | root #ifconfig usb0 |
Advanced network settings
The DHCP is very quick, but the default settings don’t give you as much freedom as you may want.
A possible scenario is that you are in a corporate, protected LAN context that doesn’t give you the Internet connection but where you need to stay connected to have access to some Intranet resource.
Or maybe you have a free but limited connection (a public wifi allowing http only, an evil firewall, etc.). Since mobile connections could be expensive, you could want to save your money up using the tethering only when needed.
Here is a handful of examples about the DHCP usage.
If you want to limit the information set by DHPC, you can fine-tune its behaviour.
E.g.:root #dhcpcd --nogateway --nohook resolv.conf --nohook hostname usb0
This will let your default gateway, resolv.conf and hostname as they are, letting you provide extra info by hand.
E.g.:root #route add -host my_sshd_remote_host_IP dev usb0
Finally, you can permanently configure your USB network interface.
E.g.
1 | FILE /etc/conf.d/net |
Generally, you can avoid every DHCP setting (see the man page) but gather them with
root #dhcpcd -U usb0
Then you can set what you want in the postup hook.