CentOS启用iptables防火墙,centos启用iptables


  其实这些东西应该一弄完就写就比较清楚了,都弄完好久了再写,可能有些地方没写到,希望看到的童鞋帮忙补充,我再更新,有错误请批评指正。

  在7.0之前貌似都是用的iptables为防火墙的,在7.0以后都是firewall,其实我也不知道为嘛,但是大部分人都是用iptables,so我也用它了。

  一、关闭firewall

1 //停止firewall 2 sudo systemctl stop firewalld.service 3 //禁止firewall开机启动 4 sudo systemctl disable firewalld.service View Code

  二、当然就是安装iptables防火墙

  1.安装

1 //安装 2 sudo yum install iptables-services View Code

  2.配置

1 //编辑iptables,如果权限不够打开时使用sudo 2 vi /etc/sysconfig/iptables 3 //文件内容 4 # Firewall configuration written by system-config-firewall 5 # Manual customization of this file is not recommended. 6 *filter 7 :INPUT ACCEPT [0:0] 8 :FORWARD ACCEPT [0:0] 9 :OUTPUT ACCEPT [0:0] 10 -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 11 -A INPUT -p icmp -j ACCEPT 12 -A INPUT -i lo -j ACCEPT 13 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT 14 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 15 -A INPUT -j REJECT --reject-with icmp-host-prohibited 16 -A FORWARD -j REJECT --reject-with icmp-host-prohibited 17 COMMIT 18 //保存文件 19 C+C 然后:wq退出->由于受emacs的习惯这里的C就代表Ctrl,so C+C其实就是Ctrl+C,以后基本都会那么写,比较方便。 20 //重启防火墙使配置生效 21 sudo systemctl restart iptables.service 22 //设置防火墙开机启动 23 sudo systemctl enable iptables.service View Code

  OK,这时,你的iptables就已经配置好了,如果以后你还想添加端口,那么接着往下看。

  3.开放端口

1 //里面的*要替换成你要开放的端口号 2 /sbin/iptables -I INPUT -p tcp --dport * -j ACCEPT 3 //保存配置 4 /etc/rc.d/init.d/iptables save 5 //查看你更改后的iptables 6 /etc/init.d/iptables status 7 //重启iptables 8 sudo service iptables restart View Code

  好了,这些就是一些有关iptables的基本配置了,有超高难度的东西,也希望大家能告诉小二一下。

  转载请注明
  作者:李小二的春天
  地址:http://www.cnblogs.com/LittleTwoLee/p/5048771.html

相关内容