iptable-restore设置INPUT允许所有

这是我的/etc/iptables/rules.v4

*filter -A INPUT -i lo -j ACCEPT -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT # Accepts all established inbound connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allows all outbound traffic # You could modify this to only allow certain traffic -A OUTPUT -j ACCEPT # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites) -A INPUT -p tcp --dport 80 -j ACCEPT -A INPUT -p tcp --dport 443 -j ACCEPT # Allow ftp -A INPUT -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT -A OUTPUT -p tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT # Allow Active FTP Connections -A INPUT -p tcp --dport 20 -m state --state ESTABLISHED,RELATED -j ACCEPT -A OUTPUT -p tcp --sport 20 -m state --state ESTABLISHED -j ACCEPT # Allow Passive FTP Connections -A INPUT -p tcp --sport 1024: --dport 1024: -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT -A OUTPUT -p tcp --sport 1024: --dport 1024: -m state --state ESTABLISHED,RELATED -j ACCEPT # Allows SSH connections # THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT # Now you should read up on iptables rules and consider whether ssh access # for everyone is really desired. Most likely you will only allow access from certain IPs. # Allow ping -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT # log iptables denied calls (access via 'dmesg' command) -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 # Reject all other inbound - default deny unless explicitly allowed policy: -A INPUT -j REJECT -A FORWARD -j REJECT COMMIT 

根本没有火箭科学,从http://wiki.debian.org/iptables复制粘贴。 问题是,当我最后iptables恢复它,“接受所有任何地方/任何地方”规则插入每个链的开始:

 root@host:/etc/iptables# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere REJECT all -- anywhere 127.0.0.0/8 reject-with icmp-port-unreachable ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT tcp -- anywhere anywhere tcp dpt:ftp state NEW,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:ftp-data state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpts:1024:65535 state NEW,RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT icmp -- anywhere anywhere icmp echo-request LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables denied: " REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp spt:ftp state ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp spt:ftp-data state ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpts:1024:65535 state RELATED,ESTABLISHED 

我知道,在加载保存的规则之前,iptables-restore会刷新所有以前的表。 不知道那些“接受所有”的地方。 请帮助。

正如圣手所提到的,你需要确保你在手前冲洗你的所有链条。

 iptables -F OUTPUT iptables -F INPUT iptables -F FORWARD 

我也select冲洗这些政策:

 iptables --policy INPUT DROP iptables --policy FORWARD DROP iptables --policy OUTPUT DROP 

这是因为你有一个规则,允许任何地方的stream量到任何地方:

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

当然,它只允许build立会话的数据包,但iptables -L没有显示。 尝试使用iptables -L -v来获得更完整的输出。

没有潮水问题。 发生这种情况是因为您添加了一个规则来允许您的回送接口中的所有stream量。 如果你使用“iptables -L -v”,你会看到“allow all”规则只适用于本地环回接口。

你的文件缺less这个:

 :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT DROP [0:0] 

在列出的规则出现之前,您可以使用以下命令将策略设置为默认值:

 iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP 

所以如果你设置默认策略,然后运行iptables-save ,你应该看到上面的行。 保存到你的文件,并恢复与iptables-restore将工作。