How do I route traffic from WiFi Hotspot to USB?
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.