当前位置:网站首页>如何在Firewalld中为特定IP地址开放端口
如何在Firewalld中为特定IP地址开放端口
2022-08-08 18:25:00 【yuyuyuliang00】
如何在私有网络中允许来自特定IP地址的流量或者允许来自特定私有网络的流量通过firewalld到达CentOS服务器上特定端口或者服务。
我们将在这里学习如何在运行了firewalld防火墙的RHEL或CentOS服务器中为一个特定IP地址或者网络范围开放端口。
解决这个问题的最合适方式是通过使用firewalld zone。因而,你需要创建一个新zone,它将具有新的配置(或者你可以使用任何可用的安全默认zones)。
在Firewalld中为特定IP地址开放端口
首先创建一个合适的zone名称(在这里,我们使用mysql-access来允许访问MySQL数据库服务器)。
[[email protected] blctrl]# firewall-cmd --new-zone=mysql-access --permanent
success
接着,重载firewalld设置来应用这个变化。如果你跳过这个步骤,当你尝试使用这个新zone名称时,你会遇到错误。此时,新的zone会出现在zones列表中。
[[email protected] blctrl]# firewall-cmd --reload
success
[[email protected] blctrl]# firewall-cmd --get-zones
block dmz drop external home internal libvirt mysql-access nm-shared public trus ted work
[[email protected] blctrl]# firewall-cmd --get-zones
block dmz drop external home internal libvirt mysql-access nm-shared public trusted work
接着,添加源地址(192.168.50.180/24)和你想要在本地机器上开放的端口(3306)。接着重载这个firewalld设置来使用新的更改。
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --add-source=192.168.50.180 --permanent
success
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --add-port=3306/tcp --permanent
success
[[email protected] blctrl]# firewall-cmd --reload
success
另外,你能够允许来自整个网络的流量到达一个服务或端口。
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --add-source=192.168.50.0/24 --permanent
success
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --add-port=3306/tcp --permanent
success
[[email protected] blctrl]# firewall-cmd --reload
success
要确认新的zone有了以上添加的所需设置,用以下命令检测其详情情况。
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --list-all
mysql-access (active)
target: default
icmp-block-inversion: no
interfaces:
sources: 192.168.50.180
services: ssh
ports: 3306/tcp
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
从Firewalld移除端口和Zone
你可以按如下显示移除源IP地址或网络。
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --remove-source=192.168.50.180 --permanent
success
[[email protected] blctrl]# firewall-cmd --reload
success
要从一个区域移除端口,发出以下命令,并且重载firewall的设置:
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --remove-port=3306/tcp --permanent
success
[[email protected] blctrl]# firewall-cmd --reload
success
确定新的设置是否生效:
[[email protected] blctrl]# firewall-cmd --zone=mysql-access --list-all
mysql-access
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
要移除区域,运行以下命令,并且重载firewalld设置:
[[email protected] blctrl]# firewall-cmd --permanent --delete-zone=mysql-access
success
[[email protected] blctrl]# firewall-cmd --reload
success
最后,你也能够使用firewalld rich规则。这是一个示例:
[[email protected] blctrl]# firewall-cmd --permanent --zone=mysql-access --add-rich-rule='rule family="ipv4" source address="192.168.50.180" port protocol="tcp" port="3306" accept'
success
边栏推荐
- CS231n: 12 Reinforcement Learning
- Build DG will increase the amount of lead to archive log problem
- Is there any function in MAXCOMPUTE SQL to judge whether the string is a number?
- Laravel 队列消费实例和定时任务添加任务消费
- Redhat 7 Maria DB安装与配置
- QT With OpenGL(泛光)(Bloom)
- Will ODPS spark on Dataworks process data more efficiently than directly using ODPS SQL?
- ABAP 报表中如何给报表的输入参数增添 F4 Value Help 试读版
- 第4讲:SQL语句之DDL类型的数据库定义语言
- “非洲之王”传音答复投资者提问:手机产品暂无计划进入中国
猜你喜欢
随机推荐
【761. Special binary sequence】
行政区划代码(道路要素)
Dataworks上的ODPS spark处理数据会比直接用ODPS SQL效率高吗?
量子力学奇妙之旅-铁磁性来由/双态系统
CS231n: 12 Reinforcement Learning
How to add F4 Value Help trial version to the input parameters of the report in the ABAP report
一起了解分层架构&SOA架构
MogDB学习笔记-从0开始
Laravel 队列消费实例和定时任务添加任务消费
Redhat 7 Maria DB installation and configuration
JVM内存模型和结构详解(五大模型图解)
搭建企业级数据治理体系指南
数据压缩和归档(三)、tarfile
携手华为打造鲲鹏产业生态 | 麒麟信安亮相鲲鹏开发者创享日·长沙站
2021年9月电子学会图形化二级编程题解析含答案:帮小企鹅躲避暴风雪
性能问题从发现到优化一般思路
view, index
codeforces 231A.Team
Performance optimization | CPU power management from the perspective of ping delay
CS231n: 11 Generative Models