温馨提示×

centos防火墙如何配置协议

小樊
38
2025-03-05 11:05:36
栏目: 智能运维
Centos服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在CentOS系统中,配置防火墙(firewalld)以允许或拒绝特定协议,可以按照以下步骤进行:

1. 查看当前防火墙状态

首先,检查firewalld服务是否正在运行:

sudo systemctl status firewalld

如果未运行,启动它:

sudo systemctl start firewalld

2. 开启或关闭防火墙

你可以选择开启或关闭防火墙:

sudo systemctl enable firewalld  # 开启防火墙
sudo systemctl disable firewalld # 关闭防火墙

3. 查看当前开放的端口和协议

使用以下命令查看当前开放的端口和协议:

sudo firewall-cmd --list-all

4. 添加或删除端口和协议

添加端口和协议

例如,添加TCP协议的80端口(HTTP):

sudo firewall-cmd --permanent --add-port=80/tcp

添加UDP协议的53端口(DNS):

sudo firewall-cmd --permanent --add-port=53/udp

添加ICMP协议(ping):

sudo firewall-cmd --permanent --add-icmp-block=echo-request

删除端口和协议

例如,删除TCP协议的80端口:

sudo firewall-cmd --permanent --remove-port=80/tcp

删除UDP协议的53端口:

sudo firewall-cmd --permanent --remove-port=53/udp

删除ICMP协议(ping):

sudo firewall-cmd --permanent --remove-icmp-block=echo-request

5. 重新加载防火墙配置

每次修改配置后,都需要重新加载防火墙以使更改生效:

sudo firewall-cmd --reload

6. 查看特定服务的开放状态

如果你想查看某个服务是否开放,可以使用以下命令:

sudo firewall-cmd --list-services

7. 添加或删除服务

例如,添加HTTP服务:

sudo firewall-cmd --permanent --add-service=http

删除HTTP服务:

sudo firewall-cmd --permanent --remove-service=http

8. 查看特定区域的配置

firewalld支持多个区域(如public、trusted、home等),你可以查看特定区域的配置:

sudo firewall-cmd --list-all --zone=public

9. 设置默认区域

你可以设置默认区域,以便新添加的接口自动应用该区域的规则:

sudo firewall-cmd --set-default-zone=public

通过以上步骤,你可以在CentOS系统中灵活地配置firewalld防火墙,以满足你的安全需求。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:centos防火墙支持哪些协议

0