1 | iptables [-t table] command [chain] [rules] [-j target] |
1 | iptables -F |
1 2 3 4 5 | iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP #NONE 包(所有标识bit都没有设置)主要是扫描类的数据包 iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP #防止sync-flood 攻击 iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP #ALL包(所有的标注bit都被设置了)也是网络扫描的数据包 |
1 | iptables -A INPUT -i lo -j ACCEPT |
1 2 3 4 5 6 7 8 9 | iptables -A INPUT -p tcp --dport 22 -j ACCEPT # SSH iptables -A INPUT -p tcp --dport 80 -j ACCEPT # HTTP iptables -A INPUT -p tcp --dport 443 -j ACCEPT #HTTPS iptables -A INPUT -p tcp --dport 25 -j ACCEPT #SMTP iptables -A INPUT -p tcp --dport 465 -j ACCEPT #Secure SMTP iptables -A INPUT -p tcp --dport 110 -j ACCEPT #POP3 iptables -A INPUT -p tcp --dport 995 -j ACCEPT #Secure POP3 iptables -A INPUT -p tcp --dport 143 -j ACCEPT #IMAP iptables -A INPUT -p tcp --dport 993 -j ACCEPT #Secure IMAP |
1 | iptables -I INPUT -m state --state ESTABLISHED, RELATED -j ACCEPT |
1 2 3 | iptables -P OUTPUT ACCEPT iptables -P INPUT DROP |
1 | iptable -L -n |
1 | service iptables save |
1 | service iptables restart |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | </pre> #!/bin/bash # A simple iptables firewall configuration PATH=/sbin:/bin:/usr/sbin:/usr/bin; export PATH #flush/erase original rules iptables -F #清除所有已制定的rule iptables -X #清除用户自定义的chain/table iptables -Z #将所有的chain的计数和流量统计归零 #Accept localhost connetting, no matter what it is iptables -A INPUT -i lo -j ACCEPT #Accept any response package which is initiated from inside iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #block most common network attacks(recon packets and syn-flood attack) iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP #open ports for different services iptables -A INPUT -p tcp --dport 22 -j ACCEPT #SSH iptables -A INPUT -p tcp --dport 80 -j ACCEPT #HTTP #iptables -A INPUT -p tcp --dport 443 -j ACCEPT #HTTPS #iptables -A INPUT -p tcp --dport 25 -j ACCEPT #SMTP #iptables -A INPUT -p tcp --dport 465 -j ACCEPT #Secure SMTP #iptables -A INPUT -p tcp --dport 110 -j ACCEPT #POP3 #iptables -A INPUT -p tcp --dport 995 -j ACCEPT #Secure POP #ICMP configuration #To prevent ICMP DDOS,we do not allow ICMP type 8(echo-request) or limit this request with 1/second #some ICMP requests are allowed. icmp_type="0 3 4 11 12 14 16 18" for ticmp in $icmp_type do iptables -A INPUT -p icmp --icmp-type $ticmp -j ACCEPT done #iptables -A INPUT -p icmp --icmp-type 8 -m limit --limit 1/second -j ACCEPT #default policies iptables -P OUTPUT ACCEPT iptables -P INPUT DROP #save to /etc/sysconfig/iptables /etc/init.d/iptables save |
欢迎光临 吾知网 (http://175999.com/bbs/) | Powered by Discuz! X3.2 |