Linux CentOS 7默认没有安装iptables,默认的防火墙是firewalld,云吞铺子分享CentOS 7系统下iptables安装、iptables规则配置(放行或者禁用端口)教程方法:html
如下大体步骤为:先关闭firewalld防火墙,而后按照iptables,最后配置添加或者禁用端口规则,详细以下:安全
安装iptables以前先检查下当前CentOS 7系统下的firewalld防火墙状态,若是是开启状态,须要先关闭firewalld防火墙。bash
查看firewalld状态,命令:服务器
systemctl status firewalld
复制代码
开启状态:显示绿色的“active (running)”,则表明开启;
关闭状态:显示“inactive (dead)”,表明关闭。tcp
若是firewalld是开启状态,须要执行命令:测试
systemctl stop firewalld
复制代码
,关闭firewalld便可。ui
安装命令:iptables:yum install -y iptables-servicesspa
启动命令:systemctl start iptablescode
运行iptables启动命令后,能够查看下iptables是否启动成功,确保iptables启动成功 查看状态:systemctl status iptables 若是提示绿色的“active (exited)”,则iptables已经启动成功。cdn
查看默认规则命令:iptables -L 安装iptables后,能够查看下当前系统下的iptables规则,熟悉一下。
安全起见,能够先备份下当前的iptables规则,而后再修改/添加规则 备份命令:cp -a /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
云吞铺子以放行80号端口为例:
iptables -I INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
复制代码
iptables -L
复制代码
iptables-save > /etc/sysconfig/iptables
复制代码
systemctl enable iptables.service
复制代码
以上为CentOS 7系统下iptables安装、配置规则和启用的方法,前面啰嗦比较多,重点在第六步,设置完毕后重启服务器(命令:systemctl reboot)去测试刚刚配置的iptables规则吧,或者移步:云服务器 ECS Linux CentOS 7 下使用iptables服务,云吞在铺子再次提醒你们,若是以前编辑过iptables先备份再更改。