【问题标题】:Allow ssh incoming/outgoing and blocking all outgoing besides specific ports允许 ssh 传入/传出并阻止除特定端口之外的所有传出
【发布时间】:2013-11-04 20:38:40
【问题描述】:

我正在尝试创建允许传入和传出 ssh 连接的 iptable 规则,然后允许到特定端口的出站连接,然后最终丢弃任何不匹配的内容。

这些是我想出的规则,SSH 规则有效,但是当我通过隧道进入盒子时,即使我允许它,我似乎也无法访问 http(端口 80)。谁能看出错误?

#!/bin/bash
#clear iptables
iptables -F
iptables -X

#set default policy to drop
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#accept everything no matter port on localhost
iptables -A INPUT -i lo -j ACCEPT

#allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#allow input on port 22, (established connections auto accepted)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

#allow traffic going to specific outbound ports
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 6667 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 6697 -j ACCEPT
#...

#drop anything that doesnt match the rules above
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP

感谢您的宝贵时间。

【问题讨论】:

    标签: linux bash networking iptables


    【解决方案1】:

    您可能需要添加 DNS 端口,否则您可能无法解析任何主机名。

    允许 TCP 和 UDP 端口 53 的 OUTPUT 应该会有所帮助。

    【讨论】:

      【解决方案2】:

      您需要使用如下规则打开端口 80 进行输入和输出:

      iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
      iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
      

      【讨论】:

        猜你喜欢
        • 2021-03-23
        • 2019-03-18
        • 2020-11-04
        • 2019-09-04
        • 1970-01-01
        • 2017-02-10
        • 2013-06-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多