0

How I have to configure iptables for redirecting traffic between wlan0 to eth0 of a raspberry pi? In my scenario eth0 is the interface connected to the home LAN with static ip 192.168.1.199, wlan0 is the interface connected to a wireless network with the address 172.217.28.2 attributed from the wireless network dhcp gateway 172.217.28.1. My goal is to communicate with 172.217.28.1 on a web interface (port 80) from any device in my home network. What I reach on my pc browser on 192.168.1.199 has to be the same I reach on the raspberry if I surf to 172.217.28.1. Like raspberry operate as a firewall with address translation for a web server behind him

I've enabled ip forwarding with

$> sudo sysctl -w net.ipv4.ip_forward=1

and used these iptables rules

iptables -A FORWARD -i eth0 -o wlan0 -p tcp --syn --dport 80 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 172.217.28.1
iptables -t nat -A POSTROUTING -o wlan0 -p tcp --dport 80 -d 172.217.28.1 -j SNAT --to-source 172.217.28.2

but no success

1
  • it is unclear what you want to know ... please ask a direct question about the problem
    – jsotola
    May 27 at 16:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.