Y
Y
yyasha2021-08-31 11:21:59
iptables
yyasha, 2021-08-31 11:21:59

How to route iptables inside linux?

Hello, I have a raspberry pi connected to a router and it has an application to which I need to redirect all Internet traffic from ports 80 and 443 (redirect to port 30443). I do it with

iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 30443
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 30443

All setup of my iptables:
sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 30443
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 30443

Why isn't traffic going through the app?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question