O
O
oleggg12017-03-17 08:28:33
linux
oleggg1, 2017-03-17 08:28:33

How to close all ports in iptables and redirect from port 8080 to port 80?

Help me please. It is necessary through iptables to close all ports except port 8080 and redirect from port 8080 to port 80.
This is not how it works:

iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -P INPUT DROP

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mureevms, 2017-03-17
@mureevms

Apparently, the client itself is local. Doesn't work because packets from localhost don't get into the nat table.
To work on localhost, you need to add this rule:

iptables -t nat -A OUTPUT -p tcp -s 127.0.0.1 --dport 8080 -j REDIRECT --to-ports 80

L
lukashin, 2017-03-17
@lukashin

Lacks

iptables -t nat -A POSTROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80

V
Vitaly, 2017-03-17
@vshvydky

why difficulties with pre-routing and so on?
as I understand it, there is a proxy forwarding to nginx like 80 -> localhost:8080
input chain, drop
accept policy with flags set relayed
accept on port 80 of whom we want
to output everything is allowed (it turns out that all local services that will initiate the connection will work)
And everything will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question