具有默认策略的防火墙规则不起作用

我做了一个防火墙规则bash脚本为:

#!/bin/bash iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT DROP ip6tables -P INPUT DROP ip6tables -P FORWARD DROP ip6tables -P OUTPUT DROP iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT ip6tables -A INPUT -i lo -j ACCEPT ip6tables -A OUTPUT -o lo -j ACCEPT # # Outgoing and Incoming ping – on all interface # ip6tables -A INPUT -i bond0 -p ipv6-icmp -j ACCEPT ip6tables -A OUTPUT -o bond0 -p ipv6-icmp -j ACCEPT ip6tables -A INPUT -i bond1 -p ipv6-icmp -j ACCEPT ip6tables -A OUTPUT -o bond1 -p ipv6-icmp -j ACCEPT ip6tables -A INPUT -i bond2 -p ipv6-icmp -j ACCEPT ip6tables -A OUTPUT -o bond2 -p ipv6-icmp -j ACCEPT ip6tables -A INPUT -i bond3.243 -p ipv6-icmp -j ACCEPT ip6tables -A OUTPUT -o bond3.243 -p ipv6-icmp -j ACCEPT # # ssh - 22/tcp # iptables -A INPUT -i bond1 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -o bond1 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT iptables -A INPUT -i bond3.243 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -o bond3.243 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT ip6tables -A INPUT -i bond1 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT ip6tables -A OUTPUT -o bond1 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT ip6tables -A INPUT -i bond3.243 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT ip6tables -A OUTPUT -o bond3.243 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT # # Save the configuration # service iptables save service ip6tables save # # dobackup # chmod a+r /etc/sysconfig/iptables chmod a+r /etc/sysconfig/ip6tables 

现在每当我应用这个规则时,我都会丢失与我的服务器的ssh连接。 然后我需要停止ip6tables服务来取回ssh连接。

但是当我更改iptables -P OUTPUT DROP to iptables -P OUTPUT ACCEPTip6tables -P OUTPUT DROP to ip6tables -P OUTPUT ACCEPT ,然后这个规则得到实现,以及我没有失去的SSH连接。

我不确定,究竟是什么问题。 在bash文件或一些我不知道的一些错误。感谢支持。

我认为是更方便的方法来允许在没有状态控制的SSH端口入站连接,并允许出站build立和相关的连接。

尝试使用规则:

 iptables -A INPUT -i bond1 -p tcp --dport 22 -j ACCEPT iptables -A INPUT -i bond3.243 -p tcp --dport 22 -j ACCEPT iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 

您的服务器无法发送其他types的stream量,因为最后一个规则只允许发送ESTABLISHED和RELATEDtypes。