How do I route traffic from WiFi Hotspot to USB? Note:- I've found out that to achieve what I want, there is a simpler,
  more flexible way than reverse tethering. If you are ever in my
  situation, read the answer below.


I reverse tether internet from laptop via USB, and wan't to share it further by creating an Hotspot on my rooted android phone. 

I get internet not just on my browser, but everywhere including Play Store and Whatsapp, when I reverse thether it from my laptop via USB. 

The only issue is that when I start a WiFi hotspot on my phone so that other devices can share this internet, they don't get internet. How do I fix this?

Here is the commands I used to set up my phone to accept internet from my laptop:

ifconfig rndis0 10.42.0.2 netmask 255.255.255.0
route add default gw 10.42.0.1 dev rndis0
ifconfig ccmni0 0.0.0.0


Where ccmni0 is my Mobile Data interface and rndis0 is the interface from which I get internet.

Why I want to do this is irrelevant to the question, but read on if you want to.

The reason for doing all this is that me and my room mate has to share a single LAN cable. Both of us run linux and have Broadcom WiFi cards, whose linux drivers don't allow you to create an AP from the laptop. I have linux only, while my friend uses linux only at times. When he is on Windows he creates a WiFi AP from his laptop using connectify. But when he is on linux, I want to temporarily create a hotspot via by mobile to share the internet.
Although this does not specifically answer my question, I solved my problem. What I wanted to do is to share my internet with my friend via WiFi using my android mobile because my Linux powered laptop doesn't have driver support for creating WiFi APs. Broadcom sucks!

I use my mobile phone to create a WiFi network(via hotspot), connect my laptop (source of internet) and other devices that require internet to the network. Now I configure my laptop to be a gateway and configure other devices to use my laptop as gateway.

Here is the guide I followed. Lucky for me, I run Arch Linux. But this should work even if you are on some other linux distro like Ubuntu. So here it goes:


Start hotspot on your mobile and connect the laptop which has internet and the device which needs internet connection.
Create a script named start-gateway.sh with the following content.


#!/bin/bash
sysctl net.ipv4.ip_forward=1 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT




The script assumes that the interface which has internet is eth0 and you need to forward packets from wlan0 (your WiFi interface) to your Ethernet connection. So please confirm if these are the names of the interfaces from ifconfig output.


Make the script executable and you are done:

chmod u+x start-gateway.sh


Whenever you need to start the gateway, execute the script with root privileges when connected to the WiFi:

sudo ./start-gateway.sh

Now all you have to do to get internet on other devices connected to the WiFi is to set the manually set IP configuration on those devices, giving the gateway as the IP address of your new gateway. Remember that by default the gateway will be the phone which is hosting the WiFi network(which has no internet), and you need to change the gateway to the one you have created.