Android reverse USB tethering

tagged under   android   linux  


We all know what USB tethering is in android -- enabling internet connectivity on your PC via your phone. Reverse USB tethering is... well... exactly the reverse. Enabling internet connectivity on your phone via your PC. The following tutorial shows you how to set up reverse USB tethering on Linux. Also included is a shell script to automate the setup on Linux.

How to set up reverse USB tethering on Linux

  • Connect your android phone to your PC via USB and enable USB tethering from the settings on your phone.
  • Find out the new network interface that was created on your PC with the following command.

    $ ifconfig  # on your PC
    

In my case, the new network interface was usb0.

  • Enter the following commands on your Linux PC.

    $ sudo ifconfig usb0 10.42.0.1 netmask 255.255.255.0
    
    $ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
    
    $ sudo iptables -t nat -F
    
    $ sudo iptables -t nat -A POSTROUTING -j MASQUERADE
    
  • Enter the following commands on your android phone. You can either use terminal emulator or enter the command through ADB like below.

    $ adb shell busybox ifconfig
    

Note down the network interface on your android phone. Mine was rndis0.

$ adb shell ifconfig rndis0 10.42.0.2 netmask 255.255.255.0

$ adb shell route add default gw 10.42.0.1 dev rndis0

Verify internet connectivity on your phone with

$ adb shell ping 8.8.8.8

That's it. You now have internet connectivity on your android phone.

I have written a small shell script to automate the above process on Linux. You can get it with the following command.

$ wget http://pastebin.com/raw.php?i=wqVnx9Vw -O rev_usb_tether.sh

Run it on your PC with the following commands.

$ chmod +x rev_usb_tether.sh

$ ./rev_usb_tether.sh

DISCLAIMER : Some apps like gmail, play store still won't recognize the internet connection.


« older posts newer posts »



other articles you might like
  • Configuring Lenovo T440s touchpad in Linux
  • Alternatives to Truecrypt on Linux
  • Connecting to wired/wireless networks via command line
  • Linux command line tools and tricks - Part 3
  • Basic dwm setup in (L)ubuntu
  • Basic Xmonad setup in (L)ubuntu
  • EOM a.k.a End of Mail a.k.a Emacs + offlineimap + mu4e
  • First attempt at developing a Firefox addon
  • Bash script to perform super-fast file transfer using netcat and tar
  • Jekyll : Handling Github page build failure and Jekyll plugins on Github
  • Emacs newbie cheat sheet -- from a vim convert
  • ncmpcpp : ncurses based music player for Linux
  • How to create a custom CWM recovery flash-able android apps zip file in Linux via command line
  • Task Warrior - The best CLI task manager for Linux
  • Custom kernel in Ubuntu (also generate .deb package)
  • Linux command line tools and tricks - Part 2
  • Superb Linux command line tools and tricks for Linux geeks
  • How to go back to stock rom on Motorola Defy
  • ADBing into your android phone
  • Interesting last few months
  • Tested : MIUI rom on Motorola Defy
  • RSA encryption using Tcl



  • Share this post ⇒  





    blog comments powered by Disqus