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

CentOS7防火墙状态


开启状态:显示绿色的“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先备份再更改。


目录
相关文章
|
6月前
|
Linux
centos使用iptables实现nat端口转发
centos使用iptables实现nat端口转发
246 4
|
4月前
|
网络协议 Linux 网络安全
Centos7中如何打开和关闭防火墙??CentOS 7以上默认使用firewall作为防火墙改为iptables
Centos7中如何打开和关闭防火墙??CentOS 7以上默认使用firewall作为防火墙改为iptables
|
运维 安全 网络协议
Centos 运维之防火墙篇——①iptables
防火墙 一般来说,iptables和firewalld启用一个即可
202 0
|
NoSQL Linux 网络安全
CentOS使用iptables禁止某IP访问
CentOS使用iptables禁止某IP访问
543 0
|
Linux 网络安全
iptables防火墙限制 centos中有 firewalld selinux 还有 iptables
iptables防火墙限制 centos中有 firewalld selinux 还有 iptables
96 0
iptables防火墙限制 centos中有 firewalld selinux 还有 iptables
|
Linux 网络安全
centOS7.3 安装启用 iptables 记录
iptables 执行规则时,是从从规则表中从上至下顺序执行的,如果没遇到匹配的规则,就一条一条往下执行,如果遇到匹配的规则后,那么就执行本规则
135 0
|
弹性计算 网络协议 安全
|
网络协议 Linux 网络安全
CentOS 7.0关闭默认防火墙启用iptables防火墙
操作系统环境:CentOS Linux release 7.0.1406(Core) 64位CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
1350 0

热门文章

最新文章