N
N
nano_e_t_42017-02-03 18:10:08
linux
nano_e_t_4, 2017-02-03 18:10:08

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

nothing on port 80. nginx hangs on port 8080, which gives the nginx page
when a request is made to host ip: 80 from another machine, a connection refused occurs. on 8080, respectively, nginx
can’t figure out why it’s so ... tell me plz

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Erelecano Oioraen, 2017-02-04
@Erelecano

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

N
nano_e_t_4, 2017-02-06
@nano_e_t_4

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

M
Maxim Kovalenko, 2017-02-09
@maxxx_kovalenko

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 question

Ask a Question

731 491 924 answers to any question