我已经用puppet安装了tomcat。它运行在标准的8080端口上。 tomcat进程以tomcat用户身份启动。我想将所有流量从端口80重定向到8080.我的iptables设置如下所示:
纳特:
# iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere multiport dports http /* 099 forward port 80 to 8080 */ redir ports 8080
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
标准iptables:
# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT icmp -- anywhere anywhere /* 000 accept all icmp */
ACCEPT all -- anywhere anywhere /* 001 accept all to lo interface */
REJECT all -- anywhere loopback/8 /* 002 reject local traffic not on loopback interface */ reject-with icmp-port-unreachable
ACCEPT all -- anywhere anywhere /* 003 accept related established rules */ state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere multiport dports ssh /* 004 accept ssh */
ACCEPT tcp -- anywhere anywhere multiport dports http,https /* 100 allow http and https access */
DROP all -- anywhere anywhere /* 999 drop all */
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
我看到netstat显示tomcat进程正在侦听端口8080:
# netstat -tulpn | grep 80
tcp6 0 0 :::8080 :::* LISTEN 16273/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 16273/java
tcp6 0 0 :::8009 :::* LISTEN 16273/java
似乎没有什么东西在听80号港口。 telnet
在端口80和8080上拥抱该机器。
如何将所有交通从80转移到8080?
答案 0 :(得分:6)
试试这个:
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
检查流量:
sudo tcpdump -i any -n port 80
如果看不到数据包,则应检查外部防火墙。
答案 1 :(得分:0)
试试这个:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:8080
请确保您的规则不会导致其他规则出现问题。所以,确保清理一切,启动并测试。如果有效,则添加其他规则。
答案 2 :(得分:0)
我多年来一直在使用它:
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
但是,重要:这仅适用于来自网络中其他主机的流量。即,你不能这样测试:
curl localhost:8080
,也不
curl <<same-host-ip>>:8081 (the host that has the iptables configured)
要检查此配置,您需要在其他主机中。
看到你的配置似乎你不需要另一个iptables规则。