Ubuntu默認安裝是沒有開啓任何防火牆的。html
當使用service iptables status時發現提示iptables:unrecoginzed service。意思是沒法識別的服務。web
如下方法來自http://blog.csdn.net/lywzgzl/article/details/39938689,可是測試發現,此方法已經沒法在Ubuntu中使用數據庫
#在ubuntu中因爲不存在/etc/init.d/iptales文件,因此沒法使用service等命令來啓動iptables,須要用modprobe命令。 #啓動iptables modprobe ip_tables #關閉iptables(關閉命令要比啓動複雜) iptables -F iptables -X iptables -Z iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT modprobe -r ip_tables #依次執行以上命令便可關閉iptables,不然在執行modproble -r ip_tables時將會提示 #FATAL: Module ip_tables is in use.
經過以上方法,最終沒法解決,經過研究發現,以上的命令已是舊版,在新版中iptables自己不是一個服務。ubuntu
而若是要繼續使用iptables配置,能夠經過來自http://www.cnblogs.com/general0878/p/5757377.html的方法去實現:bash
一、查看系統是否安裝防火牆服務器
sudo whereis iptables
出現如上提示表示已經安裝iptables,若是沒有安裝,能夠經過如下命令安裝tcp
sudo apt-get install iptables
二、查看防火牆的配置信息測試
sudo iptables -L
三、新建規則文件spa
mkdir /etc/iptables #先新建目錄,自己無此目錄
vi /etc/iptables/rules.v4
兩條合起來的命令能夠簡化成如下寫法.net
mkdir /etc/iptables & 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 3306 -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
經過以上方法能夠在Ubuntu上正常經過,而且能夠清晰的知道其依賴關係。
再或者若是要折騰iptables的用法,能夠參考如下收集的文章進行配置:
https://serverfault.com/questions/129086/how-to-start-stop-iptables-on-ubuntu
https://help.ubuntu.com/community/IptablesHowTo
通過研究發現,在Ubuntu/Debian系統上有一個防火牆的簡化版,叫作UFW,原理仍是iptables,可是因爲iptables須要操做的表和關係不少,因此使用UFW來簡化這些操做。