Debian – Internet routing between wlan0 and ppp0

debianppproutingwifi

On my Debian Linux device, I have a USB-modem that is connected to the Internet. Its interface name is ppp0.

I also have a USB-wireless adapter, where I am hosting a Access Point. Its interface name is wlan0.

How to I route traffic between these interfaces, so that if my phone is connected to this AP, that I can access the Internet via ppp0?

EDIT 1:
I tried setting up some routing, but does not seem to work. Here are the details:

# iptables --list-rules
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o ppp0 -j ACCEPT

# iptables --list-rules -t nat
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A POSTROUTING -o ppp0 -j MASQUERADE

EDIT 2 SOLVED: I was able to solve my problem. I was using the same subnet for wlan0 and ppp0. When using different subnets for wlan0 and ppp0, everything worked fine. I also found this article useful: http://elinux.org/RPI-Wireless-Hotspot

Best Answer

You can refer to this wiki that explain a very simple and complete way of acheving what you want with iptables, This explain how to Nat your wifi interface behind you ppo interface.

Edit 1: You can also make your two interface working as a bridge aka switch but it would probably be a bit more tricky, some info about that here

Related Question