最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用FirewallD限制網(wǎng)絡(luò)訪問方式

 更新時(shí)間:2024年10月28日 14:58:48   作者:EPICS Technical  
Linux系統(tǒng)中,firewalld服務(wù)提供了一種動(dòng)態(tài)管理防火墻的能力,允許用戶配置網(wǎng)絡(luò)訪問規(guī)則,通過使用firewall-cmd命令,用戶可以輕松添加或刪除端口,服務(wù),以及白名單或黑名單IP地址,在開始之前,需要用systemctl啟用firewalld服務(wù)

使用FirewallD限制網(wǎng)絡(luò)訪問

作為一個(gè)Linux用戶,你可以使用firewalld防火墻選擇允許或限制對某些服務(wù)或者IP地址的網(wǎng)絡(luò)訪問,這是CentOS/RHEL 8以及諸如Fedora的大部分基于RHEL發(fā)行版原生的。

firewalld防火墻使用firewall-cmd命令行工具配置防火墻規(guī)則。

在我們執(zhí)行任何配置前,首先使用systemctl工具啟用firewalld服務(wù),

如下:

?[root@localhost blctrl]# systemctl enable firewalld

一旦啟用了,我們現(xiàn)在可以通過執(zhí)行以下命令啟動(dòng)firewalld:

[root@localhost blctrl]# systemctl start firewalld

你可以通過運(yùn)行以下命令驗(yàn)證firewalld的狀態(tài)并且以下輸出確認(rèn)了firewalld啟動(dòng)了并且在運(yùn)行。

[root@localhost blctrl]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2022-07-21 19:40:25 CST; 4h 8min left
     Docs: man:firewalld(1)
 Main PID: 689 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─689 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

使用firewalld配置規(guī)則

現(xiàn)在我們使firewalld運(yùn)行了,我們直接制定一些規(guī)則。

firewalld允許你添加和阻塞端口,黑名單,以及白名單IP,提供對服務(wù)器訪問的地址。

一旦完成這些配置,總是確保你為了使新規(guī)則生效重載這個(gè)防火墻。

添加一個(gè)TCP/UDP端口

添加一個(gè)端口,用于HTTPS的443,使用以下語法。

注意:你必須在這個(gè)端口號之后指定端口是TCP或UDP。

[root@localhost blctrl]# firewall-cmd --add-port=443/tcp --permanent
success

類似地,要添加一個(gè)UDP端口,按如下指定這個(gè)UDP選項(xiàng):

[root@localhost blctrl]# firewall-cmd --add-port=53/udp --permanent
success

--permanent標(biāo)記確保即使在重啟后規(guī)則有效。

阻塞一個(gè)TCP/UDP端口

TCP 80端口先前已經(jīng)被添加到了規(guī)則中了,用瀏覽器測試:

要阻塞一個(gè)TCP端口,如TCP 80,運(yùn)行以下命令:

[root@localhost blctrl]# firewall-cmd --remove-port=80/tcp --permanent
success
[root@localhost blctrl]# firewall-cmd --reload
success

再次用瀏覽器測試:

類似地,封鎖一個(gè)UDP端口,將按照相同語法:

[root@localhost blctrl]# firewall-cmd --remove-port=53/udp --permanent
success
[root@localhost blctrl]# firewall-cmd --reload
success

允許一個(gè)服務(wù)

在/etc/services文件中定義了網(wǎng)絡(luò)服務(wù)。要允許像https地服務(wù),執(zhí)行命令:

[root@localhost blctrl]# firewall-cmd --add-service=https
success

阻塞一個(gè)服務(wù)

要阻塞一個(gè)服務(wù),例如,https,執(zhí)行:

[root@localhost blctrl]# firewall-cmd --remove-service=https
success

白名單一個(gè)IP地址

要允許單個(gè)IP地址穿過防火墻,執(zhí)行命令:

[root@localhost blctrl]# firewall-cmd --permanent --add-source=192.168.3.244
success
[root@localhost blctrl]# firewall-cmd --reload
success

你也可以使用CIDR標(biāo)注允許一個(gè)IPs范圍或者整個(gè)子網(wǎng)。

例如,以255.255.255.0允許一整個(gè)子網(wǎng)。

[root@localhost blctrl]# firewall-cmd --permanent --add-source=192.168.3.0/24
success

移除一個(gè)白名單IP地址

如果你在防火墻上移除一個(gè)白名單IP,使用--remove-source標(biāo)記:

[root@localhost blctrl]# firewall-cmd --permanent --remove-source=192.168.3.244
success

對于整個(gè)子網(wǎng):

[root@localhost blctrl]# firewall-cmd --permanent --remove-source=192.168.3.0/24
success

阻塞一個(gè)IP地址:

到目前為止,我們已經(jīng)看到了你如何添加和移除端口和服務(wù)以及添加和移除白名單IPs。

阻塞一個(gè)IP地址,'rich rules'用于這個(gè)目的。

例如,要阻塞這個(gè)IP 192.168.3.244,運(yùn)行命令:

[root@localhost blctrl]# firewall-cmd --add-rich-rule="rule family='ipv4' source address='192.168.3.244' reject"
success

在192.168.3.244上進(jìn)行測試:

運(yùn)行阻塞命令前:可以ping通

[blctrl@localhost ~]$ ping -c2 192.168.3.246
PING 192.168.3.246 (192.168.3.246) 56(84) bytes of data.
64 bytes from 192.168.3.246: icmp_seq=1 ttl=64 time=0.466 ms
64 bytes from 192.168.3.246: icmp_seq=2 ttl=64 time=0.559 ms

--- 192.168.3.246 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.466/0.512/0.559/0.051 ms

運(yùn)行阻塞命令后,ping不通了

[blctrl@localhost ~]$ ping -c2 192.168.3.246
PING 192.168.3.246 (192.168.3.246) 56(84) bytes of data.
From 192.168.3.246 icmp_seq=1 Destination Port Unreachable
From 192.168.3.246 icmp_seq=2 Destination Port Unreachable

--- 192.168.3.246 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1000ms

要阻塞整個(gè)子網(wǎng),運(yùn)行:

[root@localhost blctrl]# firewall-cmd --add-rich-rule="rule family='ipv4' source address='192.168.3.0/24' reject"

保存防火墻規(guī)則

如果你對防火墻規(guī)則做了任何修改,為了立即應(yīng)用更改,你需要運(yùn)行以下命令:

[root@localhost blctrl]# firewall-cmd --reload
success

查看防火墻規(guī)則

要看一下在防火墻中所有規(guī)則,執(zhí)行這個(gè)命令:

[root@localhost blctrl]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports: 443/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
        rule family="ipv4" source address="192.168.3.244" reject

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

佳木斯市| 应城市| 洪湖市| 商河县| 石景山区| 汉阴县| 偃师市| 石泉县| 营山县| 茂名市| 紫阳县| 德保县| 砚山县| 炎陵县| 英德市| 阿克陶县| 东港市| 新泰市| 内黄县| 大悟县| 墨江| 鄂尔多斯市| 新河县| 垣曲县| 齐齐哈尔市| 大厂| 眉山市| 铁岭市| 渝北区| 萍乡市| 蒙自县| 巴彦县| 华池县| 大埔县| 舟曲县| 河源市| 巍山| 洮南市| 高淳县| 探索| 资阳市|