138
  1. My HTC G2 phone is rooted and running Cyanogenmod 7
  2. I don't have a data plan.
  3. Sometimes I want to connect the phone to the Internet when there isn't Wi-Fi, to update Market apps, backup SMS messages to Gmail, sync new contacts from Gmail, etc. Things I can't do with USB mass storage mode.
  4. I have a Windows 7 Professional computer connected to the Internet, but I'm not allowed to set up an ad-hoc Wi-Fi network. (If I do, they will notice and hunt me down.)

Is there a way for the phone to access the Internet through the USB connection to the computer? If so, how do I set it up?

2

7 Answers 7

47

I recently discovered SimpleRT which works very well with Linux (and apparently OSX as well). Simply enable USB Debugging on your device (no root required), install the APK linked from that page on your device and connect it to your PC via USB, and then run the binary on your PC.

It will set up the connection as a VPN tunnel (tun0 by default) and your device should prompt you to (a) allow SimpleRT to create/oversee the VPN connection as well as (b) whether to run it when the device is configured as a particular USB accessory (which is what the binary does).

The project does not include a pre-built binary, so I've uploaded one I built for Ubuntu (file will download).


Below is a manual method that should work on Linux or Windows: http://blog.mathieu.carbou.me/post/60454997009/reverse-usb-tethering-with-android-2-2

STEP 1:

For Windows: Install USB drivers from Android SDK

For Linux: Nothing to do

STEP 2:

On Nexus One: Connect USB cable and activate USB Tethering. You should see on linux or windows a new network interface.

STEP 3:

On Linux Computer, setup a bridge:

# usb0 is the new network interface
# eth0 is the main interface connected to internet (or a gateway)

sudo ifconfig eth0 0.0.0.0  
sudo ifconfig usb0 0.0.0.0  
sudo brctl addbr br0  
sudo brctl addif br0 eth0  
sudo brctl addif br0 usb0  
sudo ifconfig br0 up  
sudo dhclient br0

See https://help.ubuntu.com/community/NetworkConnectionBridge to setup bridges

On windows, Bridge the 2 network interfaces

STEP 4:

Setup usb0 interface of your phone. You have to options:

  1. From your computer, execute:

    ./adb shell netcfg usb0 dhcp
    
  2. Or in a root terminal on your phone, type:

    su
    netcfg usb0 dhcp
    

You should now be able to connect to Internet on your phone using your computer’s Internet connection.

Try to do a ping www.google.com to be sure !

STEP 5:

To shut down the reverse-tethering, first unbridge interfaces on your computer:

sudo ifconfig eth0 down  
sudo ifconfig usb0 down  
sudo ifconfig br0 down  
sudo brctl delbr br0  
sudo ifconfig eth0 up  
sudo dhclient eth0

Then on your phone, uncheck the USB Tethering option !

You can also use Windows to create a WiFi network (using Connectify) and connect your device to that: http://www.nexusoneforum.net/forum/nexus-one-faq-how-tos/3133-reverse-tether-getting-internet-your-phone.html

6
  • 3
    In my phone, "netcfg usb0 dhcp" should be "netcfg rdnis0 dhcp"
    – diyism
    Commented Aug 28, 2014 at 10:47
  • 3
    On my cyanogenmod 13, netcfg cannot be found :(
    – maf-soft
    Commented Aug 26, 2016 at 14:48
  • 1
    netcfg remains missing from LineageOS. You might need busybox instead. android.stackexchange.com/questions/141900/… Commented Jul 15, 2017 at 19:54
  • On running sudo ifconfig usb0 0.0.0.0 I am getting SIOCSIFADDR: No such device usb0: ERROR while getting interface flags: No such device Commented Apr 1, 2018 at 19:07
  • @user1917769 You'll have to figure out what your device names the USB interface if it's different. Commented Apr 1, 2018 at 19:38
19

There are some more possibilities -- but all of them I know of require a rooted device.

Using the Reverse Tether App

First, there's an App named Reverse Tether available for free on the Play Store (it's a limited trial, which restricts the time you can be connected -- but at least you can test this way whether your device is fully supported; the full version is about USD 5). According to an article at AndroidAuthority, setup should be as easy as 1-2-3: Plug in the USB cable, start the app, let it auto-configure (manual configuration is available as well) -- and there you go. You can also let it ask you to connect when it finds an USB-connection.

Manual methods using Wifi

I know, this is not USB -- but for completeness (and giving alternatives) I thought I might add these as well:

fiddling with the system and patching around

Several manual methods are available as well (and described e.g. at XDA) -- but they are mostly technically complex, and expecting you to patch system files; not for the every-day-user, but rather for the tech-freak.

Terminal and go

However, another nice method should just involve 3 lines in the terminal, and is described in a post here, to connect to an ad-hoc Wifi network. Basically, it should go like this:

su
ifconfig wlan0 up
iwconfig mode auto;
iwconfig wlan0 essid "your SSID" channel 11 mode auto
ifconfig wlan0 10.0.0.x netmask 255.255.255.0

manipulating some config file

Another quite easy method is also described here, and involves editing the wpa_supplicant.conf file once (manually adding your ad-hoc Wifi network).

Easy-Peasy method

Do I need to say, really? Use a Wifi router. There are even some small "Travel routers" around for less than USD 50. And then connect your phone like you use to connect it to other Wifi networks...

12

I know this is an even later answer, but it is worth mentioning it.

No rooting needed!

No app installation needed!* Which is not even possible if you do not have some other internet connection.

There is a project called gnirehtet.

  1. Install adb on to the host PC (Windows/Linux/Mac)
  2. Download the gnirehtet zip-file to the host
  3. Unzip it
  4. Run the command

That's it! For more information, read the readme file of gnirehtet on their website.

*=Behind the scenes it will install an apk file on to your device via the USB connection.

4
  • 1
    Only cross-platform full-working non-commercial answer here. Even Google Play connects (Android 9 Pie).
    – cdlvcdlv
    Commented Sep 26, 2019 at 11:25
  • @cdlvcdlv: There's no reason it shouldn't:) FWIW, this uses the Android VPN API, so anything over TCP/IPv4 or UDP/IPv4 should work. (IPv6 doesn't seem to be supported) Commented Jan 3, 2020 at 11:07
  • should be the accepted answer Commented Jul 9, 2023 at 22:57
  • this did not automagically install the apk for me, (but i used gnirehtet run as instructed by the readme) but it works either way after installing the apk manually
    – Fuseteam
    Commented Sep 27 at 14:39
7

Hey! there is an app for that

Android Usb Port Forwarding
http://www.codeproject.com/kb/android/usbportforwarding.aspx

I am a bit confused how to use it, please inform if you get it working perfectly.

2
  • 1
    This apparently requires a proxy other than the computer itself, and only supports web browsing?
    – endolith
    Commented Jun 6, 2011 at 19:05
  • 1
    It says it uses port 8080, which doesn't necessarily restrict it to web browsing, does it? I thought Market could use this, however Market uses post 5228.
    – Steve
    Commented Nov 11, 2011 at 14:01
3

I've found a good tool for reverse tethering on xda-developers forum. It's called Android Reverse Tethering. It works with Windows and requires a rooted phone.
It works fine on my HTC Desire HD running MIUI v4.

2
  • I am using this software it works perfectly fine on mt galaxy s duosgts7562. I am able to use all internet related things via reverse tethering.
    – Jasser
    Commented Jul 6, 2015 at 11:20
  • To use youtube and other such apps you require to click on the install hack button then you are ready to go.
    – Jasser
    Commented Jul 6, 2015 at 11:22
3

Android reverse tethering steps:

Note: Works only in a rooted Android phone.

  1. Connect Android device via USB.
  2. Enable USB tethering. To do so, go to Settings → More... → Tethering & mobile hotspot → Usb tethering.

  3. At host machine, the usb tethering connection may be detected by the network manager.
    Its name will be something like "Wired connection 2" (or 3).
    You must edit it's "IPV4/Method" to "Shared to other computers".

3.1. Without the network manager, you will have to do it manually:

    $ sudo ifconfig usb0 10.42.0.1 netmask 255.255.255.0 
    $ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Now, as explained here at the end of Step1 you have to modify iptables with sudo iptables -t nat -A POSTROUTING -j MASQUERADE. But... prefer allow network manager to do it if possible.

  1. At Android device, you can issue these commands using a terminal with su there, or from your host machine by using ADB:

    $ adb shell su -c "netcfg rndis0 dhcp"
    

    If it doesn't get the IP address, or if you are using some application that a static IP address is desirable like "Webkey for Android" App, then assign it manually:

    $ adb shell su -c "ifconfig rndis0 10.42.0.2 netmask 255.255.255.0"
    $ adb shell su -c "route add default gw 10.42.0.1 dev rndis0"
    

Now internet would be working in the Android phone.

To check, at adb shell or android terminal, try the command ping www.google.com.

It works for me.

2
  • 1
    My device's netcfg seems to be more limited and the manual version of step 4 fails: no such action '10.42.0.2' usage: netcfg [<interface> {dhcp|up|down}] Commented May 28, 2015 at 16:51
  • 1
    @MatthewRead the command is wrong, it is actually ifconfig rndis0 10.42.0.2 netmask 255.255.255.0, btw to see all interfaces is netcfg alone. similar instructions are detailed here Commented Feb 18, 2016 at 2:07
3

For unrooted devices

I know this is a late answer, but as all existing answers suggest that USB reverse tethering is only possible if either your device is rooted or has system support for reverse tethering, I though it'd be worth pointing out there's one more option:

I was looking for a reverse tethering solution that would work on my unrooted devices and with a MacBook, but I just could not find anything. Eventually, I started to develop my own solution. The result is an app that works on devices running Android 4.0 or higher on client side, and all major desktop OSs on the host side.

The ReverseTethering NoRoot app

The app is available on Google Play: ReverseTethering NoRoot

1
  • 1
    I couldn't get this to connect on Windows or Ubuntu, but it seemed to work on OSX. Commented Sep 25, 2016 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .