CentOS7操作系统防火墙设置和开放端口方法

 

一、firewalld常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1、查看firewall状态
systemctl status firewalld.service
 
2、开启firewall防火墙
systemctl start firewalld.service
 
3、停止firewall防火墙
systemctl stop firewalld.service
4、重启firewall防火墙
systemctl restart firewalld.service
 
5、禁止firewall开机启动
systemctl disable firewalld.service
 
6、设置开机启动firewall
systemctl enable firewalld.service

  

 

二、iptables安装和使用

 1、我们常用的iptables防火墙工具在CentOS7中默认的并没有安装,而是用的firewalld,如果我们还是喜欢使用iptables则需要安装对应的服务后才 可以使用

1
2
3
4
5
6
7
8
#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables
yum update iptables
#安装iptables-services
yum install iptables-services -y

 

 

2、我们需要禁止自带的防火墙

 

1
2
3
4
#停止firewalld服务
systemctl stop firewalld
#禁用firewalld服务
systemctl mask firewalld

 

 如果我们使用的CentOS7系统的,建议不要用iptables ,用默认的比较好。

三、端口的基本设置

 

1
2
3
4
5
6
7
8
9
10
11
12
1、开放端口
 
firewall-cmd --zone=public --add-port=80/tcp --permanent
2、重新载入
 
firewall-cmd --reload
3、查看对应端口
 
firewall-cmd --zone=public --query-port=80/tcp
4、删除端口
 
firewall-cmd --zone=public --remove-port=80/tcp --permanent

  

CentOS6到CentOS7系统中常用的命令没有太多变化,防火墙命令是变化比较大的。

 

 

posted @   大宋666  阅读(324)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示