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来简化这些操做。