Reverse tethering routes traffic from the device via host gateway over USB. This allows the Android device to access the network through the host without depending on Wifi or Bluetooth.
This method leverages VpnService API and does not require root access.
+-----------------------+ +------------------------+
| Android Device | | Linux Host |
|-----------------------| |------------------------|
| | Android | |
| ^ iptables | VpnService | ^ iptables |
| | | | | |
| +--------+ | | +--------+ |
| | tun | --------- | | tun | ---------
| +--------+ | \ | +--------+ | \
| ^ | | ^ |
| | forward() | TetherService | | forward() | forwarder
| v | | v |
| +----------+ | / | +---------------+ | /
| | unix sock| --------- | | TCP/unix sock | ------
| +----------+ | | +---------------+ |
| | | | | |
| | | | | |
| +--------+ | | +--------+ |
| | adbd | | | | adb | |
| +--------+ | | +--------+ |
| + | | + |
| | | | | |
+---------|-------------+ +----------|-------------+
| |
| |
| adb forward XXX localabstract:YYY |
+-------------------------------------------+
-
Get Android SDK and NDK. Using the SDK manager, get build tools.
-
Build the native library:
$(ANDROID_NDK)/ndk-build
-
Build the apk and install it:
ANDROID_HOME=$(ANDROID_SDK) ant debug install
-
Build the host-side forwarder:
make -C jni
-
Get Android Development Tools and Android Native Development Tools.
-
Import existing project into workspace and build.
-
Build the host-side forwarder:
make -C jni
-
Start the VPN service:
./run.sh setup # You will be asked for sudo password.
Wait for the alert dialog.
-
Start the tunnel:
./run.sh run # You will be asked for sudo password.
You should see a key icon in the status bar.
-
When done, press Enter to stop the tether.
See LICENSE.