So, I have my Glassfish server is listening on port 8080.
However, I want to have my requests at port 80 while hiding 8080,
so that people think my server really runs at 80.
How can I do it with iptables
? I have tried the following rule:
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
but it's not what I want, because I have to open both 80 and 8080 for it to work.
Any ideas?
Update: I've changed my rules' file to look like:
iptables -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -j DROP
#REDIRECTION RULES
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT \
--to-destination 127.0.0.1:8080
But still doesn't work. I have /proc/sys/net/ipv4/ip_forward
set to 1
.
Nor http://myserver:8080
neither http://myserver:80
work. The packets are dropped.