我有一些iptables规则可以将端口 80 的请求重定向到我们的应用程序服务器(GlassFish)的端口 8080(以及 SSL 端口,但为简单起见,我将它们排除在外)。
虽然我们的工作正常(我个人对此没有问题),但如果有人希望在 url 中指定它,端口 8080 也对外界开放。已强制要求将 8080 端口关闭,禁止外界访问,仅开放 80 端口。
我不希望更改应用程序服务器上的侦听器(对于使用端口 80,这似乎需要为运行应用程序服务器的用户提升权限)并且端口 8080 上的侦听器需要知道数据包的源 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