Android – USB tethering with a Linux PC

I find it convenient to share the internet connection of my Android phone with my Linux laptop. I used to do it over WiFi but WiFi tethering is causing me no end of headaches. Not only was the WiFi connection dropping all the time, I’m now unable to use it at all. I’m not sure what’s going on but I think it stopped working after an Ubuntu software update.

Anyways, these WiFi issues led me to research USB tethering as an alternative. I figured out two USB tethering methods that work with my Linux PC. The first only works with a rooted phone while the second should work without root. I also explored using the phone as a WiFi adaptor for the PC and sharing the PC’s LAN connection with the phone.

So here’s what I could figure out. I hope this can be of use to somebody.

Tethering with a rooted phone

To share the internet connection of a rooted Android phone with a Linux PC:

Tethering with an unrooted phone

I think I came up with a way of tethering an unrooted Android phones using Slirp. Slirp is an old program that let someone access the internet through a dialup Unix account. It implements PPP and NAT in user space and is designed to work without root access.

I prepared a build of Slirp for Android. It let me tether my phone which is already rooted. But I see no reason why it should require a rooted phone at all.

Using the phone as a WiFi adaptor

Interestingly both these tethering methods work the same whether the phone is using WiFi or Mobile Data. As a result an Android phone can serve as a external WiFi adaptor of sorts for the PC.

Reverse tethering

I’m also trying to figure out if (in the absence of wireless connectivity) the phone can be connected to a PC to access the internet through a wired ethernet connection. This kind of reverse tethering could be useful if we need to tweet from our phones inside a nuclear bunker or a Faraday cage don’t you think?😉

So far I can’t get this working very well. The problem is that some apps don’t recognize the connection. The Android browser for instance complains that there is “No network connection” and then proceed to load the page anyway.

I think the problem is that on the Java side of Android there’s no class for reporting the state of a ppp connection to the apps. There are in fact only two NetworkStateTracker subclasses MobileDataStateTracker and WifiStateTracker. If you see a way to work around this problem please let me know.

16 Responses to “Android – USB tethering with a Linux PC”

I’m trying to use the “non-rooted” procedure, but I bump into problems. Every step runs without any error message, it seems that the ppp connection is well set up (see output from ifconfig below), but still my linux box can’t access the internet. My phone’s connection is good though. I’m running Ubuntu 11.04 and my phone is running Android 2.2. I’m a new linux user so I don’t know what more info would be relevant to you, but don’t hesitate to ask for more details.

Reverse-tethering works like a charm ! Thanks a lot for this feature ! Even my own app works ! But Google Play doesn’t want to install applications😦 Any idea to fix this ? (and a few others apps…)
HTC Desire with Cyanogen 7.1 and Ubuntu + Debian.