# whereis iptables #檢視系統是否安裝防火牆可以看到: iptables: /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz #表示已經安裝iptables apt-get install iptables #如果預設沒有安裝,請執行此命令安裝防火牆 # iptables -L #檢視防火牆配置資訊,顯示如下: Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination # vi /etc/iptables/rules.v4 新增以下內容(備註:80是指web伺服器埠,3306是指MySQL資料庫連結埠,22是指SSH遠端管理埠.) *filter :INPUT DROP [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :syn-flood - [0:0] -A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT -A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood -A INPUT -j REJECT --reject-with icmp-host-prohibited -A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN -A syn-flood -j REJECT --reject-with icmp-port-unreachable COMMIT # iptables-restore < /etc/iptables/rules.v4 #使防火牆規則生效 # vi /etc/network/if-pre-up.d/iptables #建立檔案,新增以下內容,使防火牆開機啟動 #!/bin/bash iptables-restore < /etc/iptables/rules.v4 # chmod +x /etc/network/if-pre-up.d/iptables #新增執行許可權 # iptables -L -n檢視規則是否生效.
# whereis iptables #檢視系統是否安裝防火牆可以看到: iptables: /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz #表示已經安裝iptables apt-get install iptables #如果預設沒有安裝,請執行此命令安裝防火牆 # iptables -L #檢視防火牆配置資訊,顯示如下: Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination # vi /etc/iptables/rules.v4 新增以下內容(備註:80是指web伺服器埠,3306是指MySQL資料庫連結埠,22是指SSH遠端管理埠.) *filter :INPUT DROP [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :syn-flood - [0:0] -A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT -A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood -A INPUT -j REJECT --reject-with icmp-host-prohibited -A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN -A syn-flood -j REJECT --reject-with icmp-port-unreachable COMMIT # iptables-restore < /etc/iptables/rules.v4 #使防火牆規則生效 # vi /etc/network/if-pre-up.d/iptables #建立檔案,新增以下內容,使防火牆開機啟動 #!/bin/bash iptables-restore < /etc/iptables/rules.v4 # chmod +x /etc/network/if-pre-up.d/iptables #新增執行許可權 # iptables -L -n檢視規則是否生效.