我有一些 iptables
规则,可以将端口 80 的请求重定向到我们的应用程序服务器 (GlassFish) 的端口 8080(还有 SSL 端口,但为了简单起见,我将它们排除在外)。
虽然我们的工作正常(我个人对此没有任何问题),但如果有人希望在 url 中指定端口 8080,它也对外开放。规定8080端口要关闭,不能对外访问,只开放80端口。
我不想更改应用程序服务器上的监听器(至于使用端口 80,这似乎需要为运行应用程序服务器的用户提升权限)并且端口 8080 上的监听器需要知道源 IP数据包作为应用程序审核对应用程序的请求(即我们不能将源 IP 地址更改为本地地址)。
当前的 iptables
配置如下。有谁知道是否有办法阻止来自公共(public)互联网的 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
最佳答案
我发现实现此目的的一种方法是在 mangle 表的 PREROUTING 链中使用 MARK 目标。
添加规则来标记要阻止的数据包:
iptables -t mangle -A PREROUTING -p tcp --dport 8080 -j MARK --set-mark 1
然后,在允许端口 8080 之前将此添加到 DROP 标记的数据包中:
iptables -A INPUT -m mark --mark 1 -j DROP
关于http - iptables 将 80 重定向到 8080 但阻止公共(public) 8080 访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11065124/