当前位置:网站首页>如何在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
边栏推荐
猜你喜欢
OpenInfra Days China 2022即将开启,与 openEuler 共话开源技术
Laravel 队列消费实例和定时任务添加任务消费
How to add F4 Value Help to the input parameters of the report in the ABAP report
21天学习挑战赛——机器学习03
2021年9月电子学会图形化一级编程题解析含答案:小狗进圈
ABAP 报表中如何给报表的输入参数增添 F4 Value Help 试读版
2021年9月电子学会图形化三级编程题解析含答案:计算平均分
Transsion Holdings: At present, there is no clear plan for the company's mobile phone products to enter the Chinese market
MySQL:Update高并发下变慢的案例及其涉及的特性
一起了解分层架构&SOA架构
随机推荐
视图,索引
我们想更换RDS数据库,从sqlserver 2016 web升级到 2017企业集群版,有专家咨询
ABAP 报表中如何给报表的输入参数增添 F4 Value Help
2021年9月电子学会图形化三级编程题解析含答案:接红包游戏
2 prerequisites for successful "digital transformation" of enterprises!
what‘s the meaning of build-essential
Shell脚本三剑客(grep、sed、awk)
Task-Driven Super Resolution: Object Detection in Low-resolution Images
Zhiwen final version
21天学习挑战赛——机器学习03
MySQL:Update高并发下变慢的案例及其涉及的特性
uniapp父组件使用prop将异步的数据传给子组件
TensorFlow学习记录(七):生成对抗网络
看三年的CRUD程序员如何解决数据库死锁的
hdu1042 N! (large number)
Fortinet new cloud native protection products launched amazon cloud platform of science and technology
倒置字符串
前缀和的本质
Digital currency perpetual contract exchange development and development functions and code presentation
PG 之 huge page