- Alexandre Jasmin’s Blog
- Note: this was written back in 2011 and needs to be revised for newer Android phones .
- Tethering with a rooted phone
- Tethering with an unrooted phone
- Using the phone as a WiFi adaptor
- Reverse tethering
- Share this:
- Like this:
- Related
- 18 Responses to “Android – USB tethering with a Linux PC”
Alexandre Jasmin’s Blog
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.
Note: this was written back in 2011 and needs to be revised for newer Android phones .
Tethering with a rooted phone
To share the internet connection of a rooted Android phone with a Linux PC:
- Install the Android SDK for Linux into:
/opt/android-sdk-linux_x86 - Enable USB debugging on the phone
- Plug the phone to the PC with an USB cable
- Run this tethering shell script on the PC
- Let the script automatically enable NAT routing on the phone and setup a ppp connection…
Note that the shell script above is similar to this one from mzet but uses the new “adb ppp” command instead of sending the ppp stream over a socket.
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.
In order to use Slirp for tethering:
- Install the Android SDK for Linux into:
/opt/android-sdk-linux_x86 - Enable USB debugging on the phone
- Plug the phone to the PC with an USB cable
- Install Slirp on the phone with:
curl -O https://s3.amazonaws.com/alex-public/slirp
adb push slirp /data/local
adb shell chmod 700 /data/local/slirp - Finally run this script on the Linux PC to setup the connection.
Let me know if that works for you.
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.
If you’d like to try reverse tethering anyways:
- Install the Android SDK for Linux into:
/opt/android-sdk-linux_x86 - Enable USB debugging on the phone
- Disable WiFi and Mobile Data on the phone by long pressing the power button and selecting Airplane mode
- Plug the phone to the PC with an USB cable
- Run this reverse tethering shell script on the PC
- Let the script automatically enable NAT routing on the PC and setup a ppp connection with the phone…
Share this:
Like this:
Related
This entry was posted on July 24, 2011 at 4:16 am and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
18 Responses to “Android – USB tethering with a Linux PC”
- Alex Says:
September 30, 2011 at 5:39 am | Reply Thanks for all this information! 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. #ifconfig
eth0 Link encap:Ethernet HWaddr 00:12:3f:e2:ca:1f
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:18 eth1 Link encap:Ethernet HWaddr 00:13:ce:2b:39:05
inet6 addr: fe80::213:ceff:fe2b:3905/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:5202 errors:0 dropped:0 overruns:0 frame:0
TX packets:5742 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4573992 (4.5 MB) TX bytes:849386 (849.3 KB)
Interrupt:17 Base address:0xa000 Memory:dfcfd000-dfcfdfff lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:6712 errors:0 dropped:0 overruns:0 frame:0
TX packets:6712 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1023992 (1.0 MB) TX bytes:1023992 (1.0 MB) ppp0 Link encap:Point-to-Point Protocol
inet addr:10.0.2.15 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:33 errors:0 dropped:0 overruns:0 frame:0
TX packets:66 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:1436 (1.4 KB) TX bytes:3663 (3.6 KB) Thanks for your help - Alex Says:
September 30, 2011 at 6:44 am | Reply I found the problem! I removed the “usepeerdns” option in order to use my PC’s resolv.conf and not the phone’s (if my understanding is good). Thanks a lot for this very helpful page!! - fede Says:
February 9, 2012 at 1:21 pm | Reply Brilliant! Works out of the box (but for the sdk path) HTC Desire/Cyanogen 7.10 and Arch linux.
Thanks a million ! - Nathan Says:
June 24, 2012 at 1:05 pm | Reply 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. - Sayooj Says:
July 5, 2012 at 6:12 pm | Reply It didnt work. Android Samsung charge 2.3.6 with Macbook pro. The script went well with minor tweaking on the sdk path. Once everything is done, I turned off my Wifi connection and tried hitting the browser with URL http://www.google.com and it showed me not connected to internet. Am I missing anything ? Do i Have to change anything ? Or is it just coz of MacBook Pro ? - Sayooj Says:
July 5, 2012 at 7:02 pm | Reply Is there any way to Tether over bluetooth without rooting ? Android’d internet connection to a Laptop or any device connected thru bluetooth? - E Verbeek Says:
February 2, 2013 at 7:25 pm | Reply For some reason, my Cyanogenmod 7 install on a Nexus One gets an incorrect DNS server entry when using the reverse-tether script. I fix this manually by running: # setprop net.dns1 To see which nameserver is configured: # getprop | grep dns - Gowtham Saran D Says:
June 13, 2013 at 4:33 pm | Reply in my ubuntu 12.04 usb tethering is working normally without any configurations. but wifi tethering not working(who cares when we have alternative) Right now i am really enjoying to work in my linux netbook without any hanging issues or slowness..- cyriljm Says:
June 23, 2013 at 4:06 pm | Reply you mean you are able to your pc internet connection on mobile?
- cyriljm Says:
- Jeremy Knight Says:
July 27, 2013 at 7:17 am | Reply I am having same problem as verbeek BUMP for justice - Dan Jacobson Says:
October 31, 2014 at 6:36 am | Reply The reverse tethering steps all didn’t produce any errors. Alas none of the apps on my VITA Double II said they were connected.- 積丹尼 Dan Jacobson Says:
October 9, 2015 at 5:36 am | Reply One would think that [Xposed] Fake Wifi Connection would help, but it doesn’t. - 積丹尼 Dan Jacobson Says:
October 9, 2015 at 5:54 am | Reply journalctl -f
Using interface ppp1
Connect: ppp1 /dev/pts/3
Modem hangup
Connection terminated.
Exit.
- 積丹尼 Dan Jacobson Says:
- jose Says:
December 3, 2014 at 7:36 am | Reply Thanks works great for my Sony Xperia z3 t-mobile
I just have to manually edit resolv.Conf - sanjay Says:
March 29, 2015 at 10:18 am | Reply i am getting this erro “ppp command not found” with android 4.0.4 tablet - jose Says:
June 5, 2015 at 5:48 pm | Reply it was working on xperia z3 but ufter upgrade to loolipop need recompile shell@D6616:/data/local/tmp $ ./slirp
error: only position independent executables (PIE) are supported - alexatilbrook Says:
July 7, 2017 at 10:40 am | Reply Not working for me. Tried your unrooted instructions and got a permission denied when I tried to follow the ‘adb push slirp /data/local’ instruction. Have you thought of making it EASIER for unrooted users? Like making an APK of this? ZTE Prestige 2, Android 6.0.1, not rooted. XDA has no root strategy for this phone yet. And Azilink crashes the second I start it, so that is not an option. Oh well, it was a good idea… but you should have temporarily unrooted your phone before posting these instructions for non-rooted users.- ajasmin Says:
July 7, 2017 at 2:23 pm | Reply I’m sorry. This old post needs to be updated for newer Android versions. I’ll add a notice in the mean time.
- ajasmin Says: