1. Home

Anil

< Blog />

VPN tethering on root android through USB and wifi hotspot

in

I wanted to tether my rooted S5 android to my ASUS N66U router so I could use my mobile data connection through my router over a VPN.

Getting this working with a VPN for both USB and wifi was a little more tricky than I thought, but I found the following two solutions in the end.

For USB

Plug your phone into your router via USB and enable tethering on your android phone.

../../../_images/step1-settings.png
../../../_images/step2-enable-tether.jpg

Your router screen should go through the following steps, this may take a minute.

../../../_images/asus-disconnected.jpg
../../../_images/asus-half-connect.jpg
../../../_images/asus-full-connect.jpg

Once you’re connected and have an IP, you should be able to access the internet by connecting to your router, all your traffic is being sent over the default network. Next, connect to your VPN, I’m using OpenVPN.

../../../_images/step4-connect-vpn.jpg

Create a new file with the following contents and save it to your android device.

# Copy into /data/local/userinit.sh
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE

ip rule add from 192.168.43.0/24 lookup 61
ip rule add from 192.168.42.0/24 lookup 61
ip route add default dev tun0 scope link table 61

ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add 192.168.42.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
ip route add 172.27.232.0/24 dev tun0 table 61

We need to run this script as the root user.

I use root browser from the playstore to run my script via a GUI.

Root browser for android

Check your IP, all your traffic should now be sent over your VPN.

Note

The order you perform these steps in matters. If you’re already connected to your VPN when you enable tethering, you’ll have to disconnect and then reconnect so your router can be setup with regular tethering (before applying the VPN tunnel).

The process that worked for me is as follows:

  • Disconnect from all VPN networks
  • Plug in USB
  • Enable tethering on your device
  • Wait for the router DHCP to give an IP
  • Now we have an IP, connect to your VPN
  • Run the script as root to tunnel all traffic to your VPN

This works for USB, but for mobile hotspot / wifi tethering, you can use the next method below.


Tether android mobile hotspot / WiFi VPN

To send mobile hotspot traffic over my VPN, I had to use an app called VPN tethering.

The process here is similar, enable mobile hotspot > connect to your VPN > then open the app and click the button.

This will send all mobile hotspot traffic over your VPN.