我有一些 iptables
规则,将对端口80的请求重定向到我们的应用服务器(GlassFish)的端口8080(也包括SSL端口,但为简单起见,我已经省略了它们)。
虽然我们目前的方案很好(个人也没有问题),但是如果有人想在url中指定它,端口8080也会对外开放。现在规定必须关闭从外部访问端口8080,只开放端口80。
我不希望改变应用服务器上的监听器(因为要使用端口80,似乎需要提升运行应用服务器的用户的权限),并且端口8080上的监听器需要知道数据包的源IP地址,因为应用程序审计请求到应用程序(即我们不能将源IP地址更改为本地IP地址)。
下面是当前的 iptables
配置。请问是否有一种方法可以阻止公共互联网访问端口8080,同时保留从端口80重定向的数据包中的源IP?
非常感谢您的帮助。
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
# allow establishment of connections initialised by my outgoing packets
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# accept anything on localhost
iptables -A INPUT -i lo -j ACCEPT
################################################################
#individual ports tcp
################################################################
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
#drop everything else
iptables -A INPUT -j DROP
################################################################
#Redirection Rules
################################################################
# redirection rules (allowing forwarding from localhost)
iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8080
# redirection http
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080