Step 0: Make sure the device is booted and connected via USB
Step 1: Enable tethering on the device side
- Go to Settings
- Under the Wireless & Networks, click on More
- Click on Tethering & portable hotspot
- Enable USB Tethering
Step 3: Get the matching IP Address of the workstationmalachi@onyx:~$ adb shell
root@android:/ # netcfg
lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00
dummy0 DOWN 0.0.0.0/0 0x00000082 62:bc:02:e1:d5:ea
rmnet0 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet1 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet2 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet3 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet4 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet5 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet6 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet7 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00
rndis0 UP 192.168.42.129/24 0x00001043 da:02:11:22:14:af
Step 4: Ping the device from the workstationmalachi@onyx:~$ ifconfig -a usb0
usb0 Link encap:Ethernet HWaddr e2:31:b5:d7:f3:7b
inet addr:192.168.42.74 Bcast:192.168.42.255 Mask:255.255.255.0
inet6 addr: fe80::e031:b5ff:fed7:f37b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1990 errors:0 dropped:0 overruns:0 frame:0
TX packets:1188 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:181334 (181.3 KB) TX bytes:657452 (657.4 KB)
malachi@onyx:~$ ping 192.168.42.129
PING 192.168.42.129 (192.168.42.129) 56(84) bytes of data.
64 bytes from 192.168.42.129: icmp_req=1 ttl=64 time=1.01 ms
64 bytes from 192.168.42.129: icmp_req=2 ttl=64 time=0.605 ms
Step 5: Ping the workstation from the device
root@android:/ # ping 192.168.42.74Step 6: Add workstation as the default gateway for the device
PING 192.168.42.74 (192.168.42.74) 56(84) bytes of data.
64 bytes from 192.168.42.74: icmp_seq=1 ttl=64 time=0.427 ms
64 bytes from 192.168.42.74: icmp_seq=2 ttl=64 time=0.397 ms
Step 7: Get a list of DNS servers from the workstationroot@android:/ # route add default gw 192.168.42.74 dev rndis0
malachi@onyx:~$ cat /etc/resolv.confStep 8: Add them to the device
nameserver 172.29.224.11
nameserver 8.8.8.8
Step 9: Setup forwarding from usb0 to eth1 on the workstationroot@android:/ # setprop net.dns1 172.29.224.11
root@android:/ # setprop net.dns2 8.8.8.8
[ most people probably use eth0. Just use ifconfig to check which one is active]
malachi@onyx:~$ sudo su - root
[sudo] password for malachi:
root@onyx:~# echo 1 > /proc/sys/net/ipv4/ip_forward
root@onyx:~# exit
Step 10: ping google ;)malachi@onyx:~$ sudo iptables --flush -t nat
malachi@onyx:~$ sudo iptables --table nat --append POSTROUTING --out-interface eth1 -j MASQUERADE
malachi@onyx:~$ sudo iptables --append FORWARD --in-interface usb0 -j ACCEPT
malachi@onyx:~$ adb shellAnd finally, check things like the Browser...
root@android:/ # ping google.com
PING google.com (74.125.127.99) 56(84) bytes of data.
64 bytes from pz-in-f99.1e100.net (74.125.127.99): icmp_seq=1 ttl=51 time=11.8 ms
64 bytes from pz-in-f99.1e100.net (74.125.127.99): icmp_seq=2 ttl=51 time=11.9 ms
note: by default, if you reboot the device and set it up again, the IP on usb0 will probably be different.
ReplyDeleteNice, thanks :) Do you know where the IP on usb0 on the device come from? Any way to manually set the IP?
ReplyDeleteYou can manually set it (like you would any linux box) but I didn't have any luck when I did that
ReplyDeleteSame here, permission denied when using ifconfig so I guess one must root it :(
ReplyDeleteIt does not show the IP address of usb0 when i run this "ifconfig -a usb0". Any suggestions?
ReplyDeleteTry just 'ifconfig -a' to see which interface it is. Might be usb1 or something else for your machine.
ReplyDeleteIts showing usb0 only with no inet address. It shows up when i set it manually.
ReplyDeleteDoes the above method work if you set the usb0 interface manually?
I wouldn't expect so, but I am not in a position to test it right now.
ReplyDeletePart of this will no longer work in Marshmallow since Google removed netcfg
ReplyDeletehttps://android.googlesource.com/platform/system/core/+/19db38c