Is there a way to share my computer's Internet connection with my Android through USB?

Is there a way to share my desktop Internet connection with my Android 2.2.1 using the phone data cable?


Solution 1:

Well, it can be done with rooted 2.2+ devices. It's not simple.

Before I start, you might just find it easier to buy a cheap USB Wifi dongle and share the connection to your phone through that. It's a much more simple procedure and doesn't require root on the phone.

But here's how to do it over USB:

  1. Put your phone in USB debugging mode (in settings → applications → usb). Plug the phone in.

  2. Then you need to turn on USB tethering on the phone. On my SGS2, this sits in Settings → Wireless and network → Tethering and portable hotspots.

    At this point, a new network device will be added to the computer (usb0).

  3. Fire off the following commands to bridge eth0 and your new USB connection.

    sudo apt-get install bridge-utils
    
    sudo brctl addbr br0
    
    for i in eth0 usb0; do
        sudo ifconfig $i 0.0.0.0
        sudo brctl addif br0 $i
    done
    
    sudo ifconfig br0 up
    sudo dhclient br0 # might take a few seconds
    
  4. Then load a terminal on your phone (or use the SDK adb shell) and fire off (as root):

    netcfg usb0 dhcp
    

To reverse it all:

for i in eth0 usb0 br0; do sudo ifconfig $i down; done
sudo brctl delbr br0
sudo ifconfig eth0 up
sudo dhclient eth0

To make things slightly easier there are a few Apps out there that do the phone side of things (ASProxy for example) but you still need a rooted 2.2 device. The computer side of things can be scripted. You could even hook into udev to fire these commands off when you plug the phone in (and destroy the bridge when you unplug it).

Solution 2:

There are some old notes on Reverse USB Tethering with Android 2.2 with a Nexus One.

I've been planning to try this without rooting my HTC DHD.
It has an Internet Pass-through option which works great on Windows,
So, I wonder if this can be used on the same lines through Ubuntu...
Not tried yet -- would love to know of any first-hand experience.

Requirements from those notes are,

Android 2.2 (or an older version with a root tethering app)
ADB from Android SDK, or a rooted Android 2.2 with terminal in root mode