这个防火墙阻止input链?

我使用了一个在线工具来创build一个iptables防火墙。 基本上我只需要22和1194端口向外界开放。 但我注意到这个bash脚本有默认input,转发和输出链接受。 是阻塞所有的stream量,但这两个端口? 谢谢。

IPTABLES=/sbin/iptables # Flush, Init and Zero the 'built-in' chains $IPTABLES -F INPUT; $IPTABLES -P INPUT ACCEPT; $IPTABLES -Z INPUT $IPTABLES -F FORWARD; $IPTABLES -P FORWARD ACCEPT; $IPTABLES -Z FORWARD $IPTABLES -F OUTPUT; $IPTABLES -P OUTPUT ACCEPT; $IPTABLES -Z OUTPUT $IPTABLES -F -t nat; # Setup user-defined chains $IPTABLES -X $IPTABLES -N LINWIZ-INPUT; $IPTABLES -N REJECT-PKT; $IPTABLES -N SYN-FLOOD; $IPTABLES -A INPUT -j LINWIZ-INPUT ###################################################################### # Allow all loopback interface traffic $IPTABLES -A LINWIZ-INPUT -i lo -j ACCEPT # Block all attempts to spoof the loopback address $IPTABLES -A LINWIZ-INPUT -s 127.0.0.0/8 -j LOG --log-prefix "SPOOFED-LOOPBACK: " $IPTABLES -A LINWIZ-INPUT -s 127.0.0.0/8 -j DROP $IPTABLES -A LINWIZ-INPUT -d 127.0.0.0/8 -j LOG --log-prefix "SPOOFED-LOOPBACK: " $IPTABLES -A LINWIZ-INPUT -d 127.0.0.0/8 -j DROP # Block all attempts to spoof the local IP address $IPTABLES -A LINWIZ-INPUT -s 192.73.244.224 -j LOG --log-prefix "SPOOFED-IP: " $IPTABLES -A LINWIZ-INPUT -s 192.73.244.224 -j DROP # Block Syn Flood attacks $IPTABLES -A LINWIZ-INPUT -p tcp -m tcp --syn -j SYN-FLOOD # Ensure that TCP connections start with syn packets $IPTABLES -A LINWIZ-INPUT -p tcp -m tcp ! --syn -m state --state NEW -j LOG --log- prefix "SYN-EXPECTED: " $IPTABLES -A LINWIZ-INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP # Allow session continuation traffic $IPTABLES -A LINWIZ-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT # Allow selected TCP/IP and/or UDP services $IPTABLES -A LINWIZ-INPUT -p tcp -m tcp --dport 22 -j ACCEPT $IPTABLES -A LINWIZ-INPUT -p udp -m udp --dport 1194 -j ACCEPT # Block all other TCP/IP and UDP traffic $IPTABLES -A LINWIZ-INPUT -j REJECT-PKT ###################################################################### # Syn flood filtering chain $IPTABLES -A SYN-FLOOD -m limit --limit 1/s --limit-burst 4 -j RETURN $IPTABLES -A SYN-FLOOD -j LOG --log-prefix "SYN-FLOOD: " $IPTABLES -A SYN-FLOOD -j DROP ###################################################################### # Chain used to reject all TCP/IP, UDP and ICMP/PING packets $IPTABLES -A REJECT-PKT -p tcp -m tcp -j LOG $IPTABLES -A REJECT-PKT -p tcp -m tcp -j REJECT --reject-with tcp-reset $IPTABLES -A REJECT-PKT -p udp -m udp -j LOG $IPTABLES -A REJECT-PKT -p udp -m udp -j REJECT --reject-with icmp-port-unreachable $IPTABLES -A REJECT-PKT -p icmp -m icmp --icmp-type ping -j LOG $IPTABLES -A REJECT-PKT -p icmp -m icmp --icmp-type ping -j REJECT --reject-with icmp-host-unreachable ###################################################################### # Forward, NAT and routing $IPTABLES -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT $IPTABLES -A FORWARD -s 10.8.0.0/24 -j ACCEPT $IPTABLES -A FORWARD -j REJECT $IPTABLES -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to 192.73.244.224 $IPTABLES -t nat -A PREROUTING -p udp --dport 1004:65535 -j REDIRECT --to-port 1194 echo 1 > /proc/sys/net/ipv4/ip_forward 

iptables -L -nv

 Chain INPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 18455 2290K LINWIZ-INPUT all -- * * 0.0.0.0/0 0.0.0.0/0 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 40199 31M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 736 42865 ACCEPT all -- * * 10.8.0.0/24 0.0.0.0/0 3 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT 27445 packets, 35M bytes) num pkts bytes target prot opt in out source destination Chain LINWIZ-INPUT (1 references) num pkts bytes target prot opt in out source destination 1 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 2 0 0 LOG all -- * * 127.0.0.0/8 0.0.0.0/0 LOG flags 0 level 4 prefix `SPOOFED-LOOPBACK: ' 3 0 0 DROP all -- * * 127.0.0.0/8 0.0.0.0/0 4 0 0 LOG all -- * * 0.0.0.0/0 127.0.0.0/8 LOG flags 0 level 4 prefix `SPOOFED-LOOPBACK: ' 5 0 0 DROP all -- * * 0.0.0.0/0 127.0.0.0/8 6 0 0 LOG all -- * * 192.73.244.224 0.0.0.0/0 LOG flags 0 level 4 prefix `SPOOFED-IP: ' 7 0 0 DROP all -- * * 192.73.244.224 0.0.0.0/0 8 1160 69580 SYN-FLOOD tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp flags:0x17/0x02 9 0 0 LOG tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp flags:!0x17/0x02 state NEW LOG flags 0 level 4 prefix `SYN-EXPECTED: ' 10 0 0 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp flags:!0x17/0x02 state NEW 11 17245 2216K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 12 3 180 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 13 33 2330 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:1194 14 771 47070 REJECT-PKT all -- * * 0.0.0.0/0 0.0.0.0/0 Chain REJECT-PKT (1 references) num pkts bytes target prot opt in out source destination 1 767 46830 LOG tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp LOG flags 0 level 4 2 767 46830 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp reject-with tcp-reset 3 0 0 LOG udp -- * * 0.0.0.0/0 0.0.0.0/0 udp LOG flags 0 level 4 4 0 0 REJECT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp reject-with icmp-port-unreachable 5 4 240 LOG icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 8 LOG flags 0 level 4 6 4 240 REJECT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 8 reject-with icmp-host-unreachable Chain SYN-FLOOD (1 references) num pkts bytes target prot opt in out source destination 1 758 45460 RETURN all -- * * 0.0.0.0/0 0.0.0.0/0 limit: avg 1/sec burst 4 2 402 24120 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix `SYN-FLOOD: ' 3 402 24120 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 

这些types的自动生成系统经常会产生一些非常复杂和可怕的输出。 这导致难以阅读和难以维护的输出。 不幸的是,这可能导致防火墙configuration太难以维护,导致陈旧的configuration,甚至更糟的是没有做你认为应该做的事情。

你实际上有一些非常简单的要求,两个端口当然不需要83行。 所以为了摆脱这个繁琐的configuration,程序为你生成我的build议将是废弃它,并build立你自己的手。 为了你的目的,iptables其实很简单,结果configuration实际上是可以理解的。 除了你想要的两个端口,我会build议允许ICMP。 互联网的devise思想是全function的ICMP。 如果你想要限制ping,但完全阻塞ICMP会导致其他问题。

您的输出实际上是一个从头开始设置防火墙的shell脚本,但为了简单起见,我只是想使用RedHat衍生产品上的/etc/sysconfig/iptables内容。 这是非常相似的,但稍微清理。 如果你需要它是一个脚本,你应该能够根据需要添加相关的$IPTABLES 。 以下是您应该从头开始。

 *filter :INPUT ACCEPT :FORWARD DROP :OUTPUT ACCEPT # Allow SSH from a couple of different addresses and address blocks. # Remove '-s XXXXX' to allow access from everywhere -A INPUT -s 10.10.1.5 -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -s 10.10.50.0/24 -m tcp -p tcp --dport 22 -j ACCEPT # Allow 1194 from the same hosts -A INPUT -s 10.10.1.5 -m udp -p udp --dport 1194 -j ACCEPT -A INPUT -s 10.10.50.0/24 -m udp -p udp --dport 1194 -j ACCEPT # Now we'll block ICMP echo request (ping) then allow all other ICMP -A INPUT -p icmp --icmp-type 8 -j DROP -A INPUT -p icmp -j ACCEPT # Log everything else and drop it with no error code response. -A INPUT -j LOG --log-level 7 --log-prefix "IPTABLES Dropped: " -A INPUT -j DROP COMMIT 

在那里,只有22行,仍然包括文件的意见,并确实是你需要它。 我也可以在IPTables的IT安全社区博客基本规则集中提到一篇很棒的博客文章

对于我来说,icmp-host-unreachable(使用Ping作为源地址的IP地址)进行ping操作似乎让我头疼。

回答你的问题:这个脚本阻止除tcp(22),udp(1194)和icmp(除ping之外的所有东西)。 它也为10.8.0.0/8中的机器做NAT,通过发送从给定范围收到的数据包,并把它自己的公共IP地址192.73.244.224。 此外,该脚本还将所有来自范围为1024:6535的UDP端口的请求redirect到端口1194(VPN)。 阻止回应请求并保留所有其他ICMP数据包是否合理是另一个问题。