4

I have been attempting to get reverse tethering working on my phone. I have a Galaxy S5 (g900t), running cyanogenmod 13 (marshmallow)...rooted, and with busybox.

*Edit: I've made some progress. I ran this on my ubuntu machine:

sudo ip addr flush dev eth0
sudo ip addr flush dev usb0
sudo brctl addbr br0
sudo brctl addif br0 eth0 usb0
sudo ip link set dev br0 up
sudo dhclient br0

And then I ran this in the adb shell:

dhcptool rndis0

After doing this, I seem to have internet.

I can do wget -s google.com. However, it only works as su.

root@klte:/ # wget -s google.com
Connecting to google.com (4.59.40.99:80)
Connecting to www.google.com (4.59.40.99:80)

2000@klte:/ $ wget -s google.com
wget: bad address 'google.com'

I verified that I can do wget as a regular user when I am connected through cell network or wifi.

So my question is:

Why would I be able to apparently access the internet as su, but not as a regular user? I've checked my ifconfig and route settings, and they all look the same either as su or regular user. Does anyone see what I'm doing wrong?


Config setting printouts

These settings are all the same, whether I run them as su or not. Here is my ifconfig:

1|root@klte:/ # ifconfig rndis0
rndis0    Link encap:Ethernet  HWaddr 62:91:0C:85:FD:6B  
          inet addr:192.168.22.6  Bcast:192.168.22.255  Mask:255.255.255.0
          inet6 addr: fe80::6091:cff:fe85:fd6b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:582 errors:0 dropped:0 overruns:0 frame:0
          TX packets:126 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:62495 (61.0 KiB)  TX bytes:15839 (15.4 KiB)

And here is my route table:

root@klte:/ # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.22.1    0.0.0.0         UG    0      0        0 rndis0
192.168.22.0    *               255.255.255.0   U     0      0        0 rndis0

And it appears that my DNS servers are set correctly:

root@klte:/ # cat /etc/resolv.conf  
nameserver 8.8.4.4
nameserver 8.8.8.8
1
  • I cannot help you with all the command-line setup, but if you are willing to install an app, you could try my app ReverseTethering NoRoot: play.google.com/store/apps/…
    – FD_
    Commented May 2, 2016 at 20:10

3 Answers 3

3

I just recently stumbled across what seems to me to be a much better (or at least easier) solution for reverse tethering: gnirehtet

It sets up a VPN on the android which redirects all traffic across an adb reverse port connection. Doesn't even require root at all.

1

I know I'm answering an old question here, but I've run into the same problem with Android Nougat (LineageOS 14.1), and I might as well post the solution I found:

Run the following as root on the phone (through adb) after starting tethering:

dhcptool rndis0
ip rule add from all lookup main pref 99

(the commands to run on the computer aren't in question here; in my case, I had to modprobe usbnet and modprobe rndis-host to even see the usb0 interface, but that's a completely different problem).

The thing is, Android uses a fairly complex routing setup, with different routing tables (see below for a dump). The dhcptool rndis0 command puts the appropriate routing lines in the standard main routing table, but the main table is only consulted under a rule that says uidrange 0-0 (that is, for root). What the second line above does is force the use of the main routing table for everything. This should be undone aftewards with

ip rule del pref 99

This seems to work for me, but I'm not sure how robust it is. Maybe it subtly breaks something that I didn't realize it would. Maybe there's a higher-level Android-specific command that's better and that I don't know about.

As a reminder, one can use ip rule show to display the current routing rules, and ip route show table wlan0 to show the content of table wlan0 (say).

For reference, here are the routing rules I found on my Android once tethering was set up:

0:      from all lookup local 
10000:  from all fwmark 0xc0000/0xd0000 lookup legacy_system 
10500:  from all oif wlan0 uidrange 0-0 lookup wlan0 
10500:  from all oif rndis0 uidrange 0-0 lookup local_network 
13000:  from all fwmark 0x10063/0x1ffff lookup local_network 
13000:  from all fwmark 0x10064/0x1ffff lookup wlan0 
14000:  from all oif wlan0 lookup wlan0 
14000:  from all oif rndis0 lookup local_network 
15000:  from all fwmark 0x0/0x10000 lookup legacy_system 
16000:  from all fwmark 0x0/0x10000 lookup legacy_network 
17000:  from all fwmark 0x0/0x10000 lookup local_network 
18000:  from all iif rndis0 lookup wlan0 
19000:  from all fwmark 0x64/0x1ffff lookup wlan0 
22000:  from all fwmark 0x0/0xffff lookup wlan0 
23000:  from all fwmark 0x0/0xffff uidrange 0-0 lookup main 
32000:  from all unreachable
1

I can just confirm that 'Android 6.0.1' has the same behavior. USB reverse tethering is only working for user 'root'. For the user 'shell' it does not work.

  1. USB cable is plugin to PC with Window 7
  2. Enabled 'USB tethering' on the phone
  3. Window automatically installed 'Remote Ndis Driver'
  4. Manually enable 'Internet Connection sharing' on my LAN Ndis(I get the internet from) for the 'USB Remote Ndis'. Doing so Windows assigns 'USB Remote Ndis' the IP 192.168.137.1
    ^ by this setup on the PC is complete

Now I use "adb.exe shell" to login to android -> su -> ifconfig rndis0 192.168.137.2 netmask 255.255.255.0 -> route add default gw 192.168.137.1 dev rndis0 Now test it:

shell@j5nlte:/ $ su
root@j5nlte:/ #
root@j5nlte:/ # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.137.1   0.0.0.0         UG    0      0        0 rndis0
192.168.137.0   *               255.255.255.0   U     0      0        0 rndis0

root@j5nlte:/ # wget --s google.com
wget --s google.com
Connecting to google.com (216.58.205.238:80)
Connecting to www.google.de (172.217.20.67:80)

root@j5nlte:/ # exit
shell@j5nlte:/ $ wget --s google.com
wget --s google.com

Here it just hang's wget gives no reply and after some time: wget: bad address 'google.com'

Update: In the registry change the ICS setting HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SharedAccess\Parameters ScopeAddress "192.168.137.1" => "192.168.42.1"

since android uses that as default as you can see here: shell@j5nlte:/ $ ifconfig rndis0 rndis0 Link encap:Ethernet HWaddr E6:D3:B6:BC:7B:D4 inet addr:192.168.42.129 Bcast:192.168.42.255 Mask:255.255.255.0

now the only line that's left to enable USB reverse tethering for at least root is:

route add default gw 192.168.42.1 dev rndis0

Now I'm just experimenting with ip route ip route help ....

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .