Getting back tethering on Android Jellybean

Apparently Android >= 4.1.2 breaks tethering in some cases.

Basically you can connect to your phone but you will get no data whatsoever.

This may be fair (at least from Google’s point of view) if your mobile phone operator doesn’t allow tethering and Google wants to respect that. If, like me, you’re using a virtual operator (such as Coopvoce, which relies on TIM’s network) which clearly allows tethering (it’s written on their website), this new “feature” will break tethering for no reason and I’m not sure if such operators can or will actually do anything to fix the issue on their side.

The main reason I have an Internet connection on my phone is because my ADSL at home has poor upstream bandwidth, therefore (for lack of alternatives) I use my phone’s HSUPA connection to upload stuff for work. Breaking tethering for me means making my life more difficult.

Fortunately, in that bug report in the link above I also found part of the solution which helped me get Wireless tethering. Then I managed to enable USB tethering by myself.

This tutorial will require rooting your phone, which you will do at your own risk and googling how to do it.

Requirements:

  • Grab the Android SDK
  • Make a backup of your data (as unlocking the bootloader will erase everything)
  • Unlock your bootloader
  • Root your phone (install Superuser.apk)
  • Install “Scripts Manager” (SManager)
  • Install a Text editor

Follow these steps:

Connect your phone to your PC using the USB cable

Check your devices and their IP addresses:

(Make sure that tethering is disabled and that your 3G/2G/HSUPA connection is enabled and running)

sudo adb kill-server
sudo adb start-server
adb shell
su
netcfg

Which will give you something like the following:

lo       UP           127.0.0.1/8   0x00000049 00:00:00:00:00:00
ifb0     DOWN           0.0.0.0/0   0x00000082 22:b3:ab:4e:2b:0c
ifb1     DOWN           0.0.0.0/0   0x00000082 6e:67:b2:6f:8d:6c
sit0     DOWN           0.0.0.0/0   0x00000080 00:00:00:00:00:00
ip6tnl0  DOWN           0.0.0.0/0   0x00000080 00:00:00:00:00:00
rmnet0   UP      217.202.140.0/24   0x000010d1 00:00:00:00:00:00
rmnet1   DOWN           0.0.0.0/0   0x00001090 00:00:00:00:00:00
rmnet2   DOWN           0.0.0.0/0   0x00001090 00:00:00:00:00:00
p2p0     DOWN           0.0.0.0/0   0x00001002 a2:0b:ba:21:d1:fe
wlan0    DOWN           0.0.0.0/0   0x00001002 a0:0b:ba:21:d1:fe

In this case the interesting device is “rmnet0” (let’s call it the 3G device). Write down its name and its IP address.

Now enable USB tethering and run “netcfg” again:

lo       UP           127.0.0.1/8   0x00000049 00:00:00:00:00:00
ifb0     DOWN           0.0.0.0/0   0x00000082 22:b3:ab:4e:2b:0c
ifb1     DOWN           0.0.0.0/0   0x00000082 6e:67:b2:6f:8d:6c
sit0     DOWN           0.0.0.0/0   0x00000080 00:00:00:00:00:00
ip6tnl0  DOWN           0.0.0.0/0   0x00000080 00:00:00:00:00:00
rmnet0   UP      217.202.140.0/24   0x000010d1 00:00:00:00:00:00
rmnet1   DOWN           0.0.0.0/0   0x00001090 00:00:00:00:00:00
rmnet2   DOWN           0.0.0.0/0   0x00001090 00:00:00:00:00:00
p2p0     DOWN           0.0.0.0/0   0x00001002 a2:0b:ba:21:d1:fe
wlan0    DOWN           0.0.0.0/0   0x00001002 a0:0b:ba:21:d1:fe
rndis0   UP      192.168.42.129/24  0x00001043 c2:09:33:df:45:64

You will notice the presence of a new device (in this case “rndis0” which is the USB device). Again take note of its name and IP address (which will vary but it’s not a problem).

We can now try to route traffic using iptables.

So, for Wireless tethering (use the name of the 3G device and leave the IP address as it is):

iptables -tnat -A natctrl_nat_POSTROUTING -s 192.168.0.0/16 -o rmnet0 -j MASQUERADE

And for USB tethering (use the name of the USB device and use the IP address of the 3G device):

iptables -tnat -A natctrl_nat_POSTROUTING -s 217.202.140.0/24 -o rndis0 -j MASQUERADE

Note: I’m not very familiar with iptables but I’ve found these commands to solve the problem here.

Test tethering using a PC. If it works, then we can save the two lines above in a script.

Open a text editor from your phone and type (or you can write it on your PC and then push it to your phone using adb push):

#!/system/bin/sh
iptables -tnat -A natctrl_nat_POSTROUTING -s 192.168.0.0/16 -o rmnet0 -j MASQUERADE
iptables -tnat -A natctrl_nat_POSTROUTING -s 217.202.140.0/24 -o rndis0 -j MASQUERADE

 

Then save the file, open it using SManager and tap on the “Boot” and on the “Su” labels (since we want this to run on boot and it requires root privileges).

Note: Make sure to give SManager root permissions when the Superuser app asks you.

And that’s it, restart your phone and everything should work flawlessly from now on.

One thought on “Getting back tethering on Android Jellybean

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.