如何在私有網(wǎng)絡(luò)中允許來自特定IP地址的流量或者允許來自特定私有網(wǎng)絡(luò)的流量通過firewalld到達(dá)CentOS服務(wù)器上特定端口或者服務(wù)。
我們將在這里學(xué)習(xí)如何在運(yùn)行了firewalld防火墻的RHEL或CentOS服務(wù)器中為一個(gè)特定IP地址或者網(wǎng)絡(luò)范圍開放端口。
解決這個(gè)問題的最合適方式是通過使用firewalld zone。因而,你需要?jiǎng)?chuàng)建一個(gè)新zone,它將具有新的配置(或者你可以使用任何可用的安全默認(rèn)zones)。
在Firewalld中為特定IP地址開放端口
首先創(chuàng)建一個(gè)合適的zone名稱(在這里,我們使用mysql-access來允許訪問MySQL數(shù)據(jù)庫服務(wù)器)。
[root@AlmaLinux blctrl]# firewall-cmd --new-zone=mysql-access --permanent
success
接著,重載firewalld設(shè)置來應(yīng)用這個(gè)變化。如果你跳過這個(gè)步驟,當(dāng)你嘗試使用這個(gè)新zone名稱時(shí),你會(huì)遇到錯(cuò)誤。此時(shí),新的zone會(huì)出現(xiàn)在zones列表中。
[root@AlmaLinux blctrl]# firewall-cmd --reload
success
[root@AlmaLinux blctrl]# firewall-cmd --get-zones
block dmz drop external home internal libvirt mysql-access nm-shared public trus ted work
[root@AlmaLinux blctrl]# firewall-cmd --get-zones
block dmz drop external home internal libvirt mysql-access nm-shared public trusted work
接著,添加源地址(192.168.50.180/24)和你想要在本地機(jī)器上開放的端口(3306)。接著重載這個(gè)firewalld設(shè)置來使用新的更改。
[root@AlmaLinux blctrl]# firewall-cmd --zone=mysql-access --add-source=192.168.50.180 --permanent
success
[root@AlmaLinux blctrl]# firewall-cmd --zone=mysql-access --add-port=3306/tcp --permanent
success
[root@AlmaLinux blctrl]# firewall-cmd --reload
success
另外,你能夠允許來自整個(gè)網(wǎng)絡(luò)的流量到達(dá)一個(gè)服務(wù)或端口。
[root@AlmaLinux blctrl]# firewall-cmd --zone=mysql-access --add-source=192.168.50.0/24 --permanent
success
[root@AlmaLinux blctrl]# firewall-cmd --zone=mysql-access --add-port=3306/tcp --permanent
success
[root@AlmaLinux blctrl]# firewall-cmd --reload
success
要確認(rèn)新的zone有了以上添加的所需設(shè)置,用以下命令檢測其詳情情況。
[root@AlmaLinux 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地址或網(wǎng)絡(luò)。
[root@AlmaLinux blctrl]# firewall-cmd --zone=mysql-access --remove-source=192.168.50.180 --permanent
success
[root@AlmaLinux blctrl]# firewall-cmd --reload
success
要從一個(gè)區(qū)域移除端口,發(fā)出以下命令,并且重載firewall的設(shè)置:
[root@AlmaLinux blctrl]# firewall-cmd --zone=mysql-access --remove-port=3306/tcp --permanent
success
[root@AlmaLinux blctrl]# firewall-cmd --reload
success
確定新的設(shè)置是否生效:
[root@AlmaLinux 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:
要移除區(qū)域,運(yùn)行以下命令,并且重載firewalld設(shè)置:文章來源:http://www.zghlxwxcb.cn/news/detail-465001.html
[root@AlmaLinux blctrl]# firewall-cmd --permanent --delete-zone=mysql-access
success
[root@AlmaLinux blctrl]# firewall-cmd --reload
success
最后,你也能夠使用firewalld rich規(guī)則。這是一個(gè)示例:文章來源地址http://www.zghlxwxcb.cn/news/detail-465001.html
[root@AlmaLinux 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
到了這里,關(guān)于如何在Firewalld中為特定IP地址開放端口的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!