Answer the question
In order to leave comments, you need to log in
How to do port forwarding with iptables?
Hello everyone
. I know that the topic is hackneyed and there are a lot of such questions on the Internet (because I myself rummaged and checked everything in practice), but the problem still remains:
you need to make an elementary forwarding of incoming traffic from port 80 to port 8080. iptables is clean . that is, they are generally clean, nothing is written in any plate / chain ...
I do it like this:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
Answer the question
In order to leave comments, you need to log in
And you did not try to specify the interface?
iptables -t nat -A PREROUTING -i ethN -p tcp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumber
tried. does not help :( and indicated both one at a time (as a result there were 3 rules, on eth0 eth1 b lo) and -i all
The port redirect rule is correct:
Add more forwarding rules:
#-A FORWARD -i eth0 -o eth1 -j ACCEPT
#-A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -d $LOCAL_IP -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
I also recommend reading https://www.opennet.ru/base/net/nat_redirect.txt.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question