Android -access internet from computer via USB | Reverse USB Tether




Eversince my wife delivered a baby boy, I have stopped using wifi at home to avoid any possible affect on my boy. Until then I was able to sync my phone & access internet through wifi. Now I had to find alternative.

Since Android supports pc internet/ USB tether, I tried to configure it for reverse use.
Following is the steps to get internet on android device via usb.

On Android Device
STEP 1) Root your phone. Root using SuperoneClick
STEP 2) When you connect usb cable, choose pc internet. (For Eclair)
Or
Settings –> Wireless and network –> Tethering — USB tethering (For Froyo)

(If you are using Eclair, IP network will be 192.168.1.0/24 whereas with froyo it is 192.168.42.0/24. This may be different. You can find ip network by netcfg command on android OR by ip range of usb0 device)
STEP 3) save following commands as /sdcard/and.sh (you can save it anywhere with any filename)

ifconfig usb0 192.168.1.25 netmask 255.255.255.0
route add default gw 192.168.1.100 dev usb0
setprop net.dns1 4.2.2.2
netcfg

Following is why we used above commands.
Line 1
When you choose pc internet, android acts as dhcp server & provides ip 192.168.1.100 to computer. Whereas android itself picks 192.168.1.254.
In above script first of all we are changing default ip 192.168.1.254 to 192.168.1.25, reason being when ip is leased to a computer, 192.168.1.254 is registered as dns server. Which may make your internet inaccessible on computer. Changing it to 192.168.1.25 will make 192.168.1.254 dns server inaccessible & has no effect on internet.

Line 2
Since 192.168.1.100 is the machine we are going to get internet from, it should be set as default gateway for android device.

Line 3
This will configure 4.2.2.2 as default dns, you may use your isp dns servers.


Line 4
Will display change of ip address for usb0

STEP 4) use connectbot or any other app to access shell & change permission for script.

su
chmod 777 /sdcard/and.sh

STEP 5) run scrip using following command

su
. /sdcard/and.sh

On Computer
STEP 6) once you connect usb cable & choose pc internet on android, additional interface usb0 will be detected on Fedora / Ubuntu which will get ip 192.168.1.100 from android dhcp

STEP 7) Keep following commands in /etc/rc.local Or run whenever you connect android phone.

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Or
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE

Line 1 is for ip forwarding
Line 2 is to masquerade through eth0, this is internet source interface on your computer.

If you are using slitaz latest cooking version, it does not detect ip from dhcp by default.
here you can add ip for usb0 device using following command.

ifconfig usb0 192.168.1.100 netmask 255.255.255.0 up

This is all.
Now you should be able to access internet on your android phone using usb cable.

Eclair
Except for Chat & Installing application from Market I was able to sync my phone.

Froyo
Apart from Chat & Installing application from android market, Gmail is not being synced. Whereas applications like greader / k-9 mail works fine.

I have tested this only on Samsung Galaxy 3 (GT-I5801)


if you find any missing point in here, please let us know in comment section or tweet us at @linuxreaders. To get more articles like this, subscribe to our RSS feeds / Mails.
Read 240 articles by
  • jak

    how i connect the internet from my PC to my Sony Ericson xperia x10mini phone

    • http://www.linuxreaders.com/ Dhaval Thakar

      You need rooted device. Refer this post to access internet via linux machine (not PC) to your device

  • Kevin Chadwick

    Of course most wi-fi (2.4Ghz) is at the microwave band and so the resonance of water which would make sense as to it being more dangerous in terms of cancer e.g.. cell irritation at the time of multiplying. I’m guessing from the videos of bridges collapsing that resonance can have a far greater effect than 10 times?

  • okuboyejo damilola

    hi guys, I saw this and thought of sharing it. o was using pdanet and easytether then discover d google engineers have this inbuilt. Android Tether Instructions 1. Connect your Google Android phone to a computer via USB cable 2. Open Settings then select Wireless & Networks 3. Scroll down and select Tethering & portable hotspot 4. Select USB tethering to enable the USB tethering service

    • http://www.linuxreaders.com/ Dhaval Thakar

      My friend you are talking about usb tether, here we are doing reverse usb tethering.

      • Radhe

        Dear Dhaval , plz help me, how to access internet through my Samsung 5510 Galaxy Y Pro on my Laptop . I tried below method Android Tether Instructions 1. Connect your Google Android phone to a computer via USB cable 2. Open Settings then select Wireless & Networks 3. Scroll down and select Tethering & portable hotspot 4. Select USB tethering to enable the USB tethering service but unable to connect internet plz help thanks & regards

        • http://www.linuxreaders.com/ Dhaval Thakar

          correct me if am wrong you are trying to access internet on your laptop via 2g/3g data connection available on your phone, using usb cable. Using usb 1) connect usb to your laptop 2) settings -> tethering -> usb tethering. now you should be able to access internet on your laptop Using wifi 1) settings –> mobile ap –> mobile ap 2) select & connect to newly available ap on your laptop wifi

  • NDEAN

    Can’t an APK be made to simplify these? Surely there’s some IPTABLEs to config too. Those with WIFI problems, get off this thread, this is for getting INTERNET CONNECTION FROM YOUR COMPUTER/LAN –> ANDROID (via USB). For WIFI, get connected to AP, key in the password, we’re on. We all know that, it eats up the battery though. THAT’S THE PROBLEM.

    • Jalvath

      Hi All, Thanks for all your informations. But I am now facing a different issue(Might be an older issue) and still it is failing in my android phone. The scenario is: STEP1. I want to access internet in my linux machine using android phone USB tethering. STEP2. For this I connected my android phone to an Access point and the AP in background it is connected to the broadband. STEP3. I also connected my linux machine to the android phone using USB. STEP4. After this I enabled the USB tethering in android phone. STEP5. Now the usb0 interface is up in my linux machine and it got the ipaddress in 192.168.42.x STEP 6. In my android phone the netcfg command gives the below information. # netcfg lo UP 127.0.0.1 255.0.0.0 0×00000049 veth0 DOWN 0.0.0.0 0.0.0.0 0×00001002 usb0 UP 192.168.42.129 255.255.255.0 0×00001043 sit0 DOWN 0.0.0.0 0.0.0.0 0×00000080 ip6tnl0 DOWN 0.0.0.0 0.0.0.0 0×00000080 wlan0 UP 192.168.1.101 255.255.255.0 0×00001043 STEP 7. Ping form linux machine to android USB0 interface is success. ping 192.168.42.129 – success STEP 8. Ping form linux machine to android WLAN0 interface is success. ping 192.168.1.101 – success STEP 9. Ping form linux machine to Access Point is Failing. ping 192.168.1.1 – fails. STEP 10. The tcpdump in android phone shows that ping request is coming from the linux machine and it is going to the AP. The other way for the response is also success as below. But still I am not getting the reply in the linux machine. 05:55:08.965000 IP 192.168.42.156 > 192.168.1.1: ICMP echo request, id 4033, seq 6, length 64 05:55:08.969000 IP 192.168.1.1 > 192.168.42.156: ICMP echo reply, id 4033, seq 6, length 64 STEP 11. The iptable in android is also configured as expected. I am not sure why the ping is failing. Please put some lights where could be the issue in my setup. Thanks In advance, Jalvath

      • http://www.linuxreaders.com/ Dhaval Thakar

        If you are tying to use internet on linux box via android usb tether.. all you need is enable usb tether, ideally this is how it should work. I have been using it whenever my broadband died, the only diff is I am using it via mobile network. even checked with AP, it works fine. also there is no need for any kind of iptables on phone / linux box android will manage natting on its own.

      • Gul

        Yep: works with mobile network but not on wifi -well, not on my Fedora 16 / Android gingerbread P500 setup. nslookup seems to work though. Any news or solutions? G

    • http://www.linuxreaders.com/ Dhaval Thakar

      Sure APK, but I am not developer. I am Linux Admin. If I find any app related close to what we do here, I’ll surely post.

  • Rajesh (@rajespande)

    thanks for posting this. You saved my life :) The google’s android doesnot have an ad hoc I managed to use an ad-hoc but it stopped working the next day. I used windows 7 in my laptop, Android honeycomb samsung galaxy y in my phone. Got it rooted. Followed your suggestions except “use linux” for masquerading option, I used “internet sharing ” option in windows. 1. enabled usb tethering android ip: 192.168.1.254 then : ifconfig usb0 192.168.1.25 netmask 255.255.255.0 route add default gw 192.168.1.100 dev usb0 setprop net.dns1 4.2.2.2 netcfg this worked like a charm :) thanks dude..

  • Jorge

    I managed to do this and I have internet in my phone, but market does not download, gtalk does not log in … as you said. Do you have some clue why? Port forwarding? All out traffic out of ports 80 and 443 is blocked by Android per USB connection? … Thanks for your help.

    • http://www.linuxreaders.com/ Dhaval Thakar

      no clue why, but non-google apps works fine.

    • daniele carbone

      hi Jorge have you resolved now ? does google apps work ? i need too

  • http://tamashi.ge tamashebi

    i have problem. iant share internet please. samsung galaxy i9003

    • http://www.linuxreaders.com/ Dhaval Thakar

      1) is your phone rooted? 2) have you run iptables command on linux box? 3) check output of netcfg on you phone, gateway should be your comp

  • mostafa

    thanks 4 everything. i have a galaxy s ii and i did everything u told & everything was ok until step 4 i have a problem with using connectbot it has 3 mode ( ssh &telent & local ) and it just work in local mode and with a error to dial with step 7 plz guide me. thanks!

    • http://www.linuxreaders.com/ Dhaval Thakar

      STEP4: yes, this will work with local mode only. you can connect to localhost using local mode. once connected verify root access with command su STEP7: this step to be performed on your linux machine.

  • sagar

    do sum video tutorial………….plz…………

  • sagar

    any simple way to understand…………..create sum software…its so complicated… or do for xp,win7…………..

    • http://www.linuxreaders.com/ Dhaval Thakar

      try this http://www.best-4-u.com/simple-trick-for-share-internet-connection-between-pc-and-android-phone-using-wifi.html

  • chugori

    thanks for sharing Nice info buddy, I have Huawai Ideos U8150 running Android 2.2 and i want to know how can i do followings; 1) access internet from computer via USB on winXP 2) some one told me MS Acive Sync solves it but its is not working, may be i dont know the exact process for how to configure things on MS ActiveSync and Android Network settings 3) Want to watch flash on my android device Please help me out for above three issue. I would be very greatful for you kind act…. Regards Chugori

  • oscar

    Hi, Keep in mind that smartphones using GSM are transmitting/receiving at 1Watt whereas wifi is 100mili watts (so 10 times less!) So if you’re concerned, maybe try first to limit the GSM/3G waves. Regards, Oscar

    • http://www.linuxreaders.com/ Dhaval Thakar

      :) Thats something not feasible but wifi is what I can.

  • Andrews Wardo

    How to do this in Windows XP? I installed the software, rooted and now what to do in windows XP?

    • http://www.linuxreaders.com/ Dhaval Thakar

      Have not found any way to do it on XP but win 7 has app for this.

      • ALOK

        which software in Win 7 ?? I am very curious……

        • http://www.linuxreaders.com/ Dhaval Thakar

          this might help but for wifi only http://www.maryfi.com/

  • Gronux

    thank’s , that’s work fine with web browser but it fail with gmail synchronize , an other hack :-)

  • Pingback: Android -access internet from computer via USB | LinuxReaders | DNS Internet

Trending Posts