【发布时间】:2020-08-24 11:42:44
【问题描述】:
我有一些 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
【问题讨论】:
-
您是否考虑过阻塞端口 8080 并在 httpd proxypass 上进行中继?
-
感谢您的建议。目前此服务器上没有可用的 apache 或 mod_proxy(我知道它需要..?),但很明显,如果 iptables 或标准 Linux 软件包无法实现,那么我想这是需要研究的东西。
标签: http redirect port iptables