laz*_*dar 21 port redirect http iptables
我有一些iptables规则将端口80的请求重定向到端口8080的应用服务器(GlassFish)(以及SSL端口,但为了简单起见,我将它们遗漏了).
虽然我们的工作正常(而且我个人也没有问题)如果有人希望在网址中指定端口8080,那么端口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
小智 21
我发现实现此目的的一种方法是在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