CentOS 7下iptables配置添加修改规则端口方法 | 您所在的位置:网站首页 › iptables永久保存规则 › CentOS 7下iptables配置添加修改规则端口方法 |
Linux CentOS 7默认没有安装iptables,默认的防火墙是firewalld,云吞铺子分享CentOS 7系统下iptables安装、iptables规则配置(放行或者禁用端口)教程方法: 以下大致步骤为:先关闭firewalld防火墙,然后按照iptables,最后配置添加或者禁用端口规则,详细如下: 检查firewalld并禁用安装iptables之前先检查下当前CentOS 7系统下的firewalld防火墙状态,如果是开启状态,需要先关闭firewalld防火墙。 先查看firewalld状态查看firewalld状态,命令: systemctl status firewalld开启状态:显示绿色的“active (running)”,则代表开启; 关闭状态:显示“inactive (dead)”,代表关闭。 再关闭firewalld如果firewalld是开启状态,需要执行命令: systemctl stop firewalld,关闭firewalld即可。 一:安装iptables安装命令:iptables:yum install -y iptables-services 二:启动iptables启动命令:systemctl start iptables 三:查看当前iptables状态运行iptables启动命令后,可以查看下iptables是否启动成功,确保iptables启动成功查看状态:systemctl status iptables如果提示绿色的“active (exited)”,则iptables已经启动成功。 四:查看iptables默认规则查看默认规则命令:iptables -L安装iptables后,可以查看下当前系统下的iptables规则,熟悉一下。 五:备份iptables规则安全起见,可以先备份下当前的iptables规则,然后再修改/添加规则备份命令:cp -a /etc/sysconfig/iptables /etc/sysconfig/iptables.bak 六:添加或修改规则(放行或禁用端口)云吞铺子以放行80号端口为例: 1、添加以下规则可以放行80端口命令: iptables -I INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT 2、查看规则是否生效,命令: iptables -L 3、生效后保存添加的规则,命令: iptables-save > /etc/sysconfig/iptables 4、设置iptables开启启动,命令: systemctl enable iptables.service以上为CentOS 7系统下iptables安装、配置规则和启用的方法,前面啰嗦比较多,重点在第六步,设置完毕后重启服务器(命令:systemctl reboot)去测试刚刚配置的iptables规则吧,或者移步:云服务器 ECS Linux CentOS 7 下使用iptables服务,再次提醒大家,如果之前编辑过iptables先备份再更改。 |
CopyRight 2018-2019 实验室设备网 版权所有 |