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)
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 184.108.40.206 netcfg
Following is why we used above commands.
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.
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.
This will configure 220.127.116.11 as default dns, you may use your isp dns servers.
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
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.
Except for Chat & Installing application from Market I was able to sync my phone.
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.