I know that the topic of Android tethering is old and dry. But there is just one more use case we need to address.

In this world, some stupid wireless access points will restrict the number of devices you can connect to it (and ask for a good price if you simply want more). All right. At this time, a router is your best friend. Take it with you anywhere, anywhere, anywhere so that you can always connect at least tens or hundreds of devices at the same time.

However, what if you don’t have a router but only have an Android device? An Android device can be used as a router (using Wi-Fi hotspot and USB tethering) to help another Android device get online. But there are some caveats.

First, both Wi-Fi hotspot and USB tethering will run the Android device as gateway. But sometimes we may want it to be a client in the LAN.

Second, some applications won’t work if the Android system says it’s not online (while in fact it is). Therefore it may happen that you are able to ping a website but not able to open it in the browser.

Finally, DNS setting is tricky. It seems that Wi-Fi hotspot doesn’t broadcast DNS settings when the Android device doesn’t have such settings. But for the device to have valid DNS settings, there must be valid, online interfaces known to the system (the Android framework). However, both USB and Wi-Fi will be used for tethering and the system won’t find any valid, online interface. Chicken and eggs.

So I’m here to solve this problem. Suppose you have a laptop and two Android devices A and B, and a working wireless Internet connection which only allows one interface to be connected. Our goal is:

  1. Let the laptop connect to the Internet normally.

  2. At the same time, Let device B connect to the Internet normally through a Wi-Fi link (as Wi-Fi seems to be the only interface on Android which makes all applications happy).

By the way, we don’t consider cellular data here.

Steps

  1. Connect laptop to the wireless connection. And Goal 1 is achieved.

  2. Connect device A to laptop via USB and activate USB tethering on device A. This will make the laptop use device A as a gateway on the USB interface. But what we want is reverse tethering. So:

    1. Fix ip routes on the laptop.
    2. Enable IP forwarding and configure iptables on the laptop.
    3. Set laptop as the default gateway on device A.

    At this time, the laptop should still work normally. And you should be able to ping IP addresses on device A. DNS may not work. Apps may not work. But we don’t care.

  3. Activate Wi-Fi hotspot on device A. Clean up iptables (nat and filter) to let IP packets go through between USB and wireless interfaces.

  4. Connect to the Wi-Fi hotspot on device B. This will tell the Android system that there is a working Internet connection. Unfortunately DNS settings may not be broadcast (because the system thinks device A doesn’t have any working, online interface). So you may have to set it by yourself. The method ranges from setprop to ndc resolver. I believe you can find it.

  5. After all these steps, your laptop should still work normally. And at the same time, you should be able to download/install apps from Google Play. This is usually a sign of a working Internet connection that makes many (if not all) applications happy.

It’s boring.

A Better Solution

Actually there is a better solution which doesn’t need device A at all.

  1. Connect laptop to the wireless connection. Make sure it’s connected first and so favored by the access point. Laptop is now working.

  2. Connect device B to laptop using USB reverse tethering. Configuration is the same as above (for device A).

  3. Now device B has a working Internet connection (USB). It also has an activated interface (wireless) which makes the system happy. I thought the DNS may be a problem. Well, may or may not. If the access point doesn’t assign one, set it by yourself.