# 基本防火牆設定

##### **1 直接關閉防火牆設定**

如果單位內已經有了對外的硬體防火牆設定，那麼可以考慮將本機的防火牆全數關閉，指令如下：

```shell
$ sudo systemctl disable firwalld
$ sudo systemctl stop firewalld
```

##### **2 開啟網站服務**

有些資訊要求等級高的單位，可能還是需要開啟本機防火牆，Rocky Linux 預設會啟用防火牆規則，一開始只會開放 SSH 的服務，可使用以下指令查詢：

> $ sudo firewall-cmd --zone=public --list-all  
> public (active)  
>  target: default  
>  icmp-block-inversion: no  
>  interfaces: ens18  
>  sources:  
>  services: <span style="color: #e03e2d;">**cockpit dhcpv6-client ssh**</span>  
>  ports:  
>  protocols:  
>  forward: no  
>  masquerade: no  
>  forward-ports:  
>  source-ports:  
>  icmp-blocks:  
>  rich rules:

如果要開啟網站服務(http、https)的話，可以使用以下指令開啟。

```shell
$ sudo firewall-cmd --zone=public --permanent --add-service=http 
$ sudo firewall-cmd --zone=public --permanent --add-service=https
$ sudo systemctl restart firewalld
```

再查詢一次防火牆的狀態：

> $ sudo firewall-cmd --zone=public --list-all  
> public (active)  
>  target: default  
>  icmp-block-inversion: no  
>  interfaces: ens18  
>  sources:  
>  services: cockpit dhcpv6-client **<span style="color: #e03e2d;">http https</span>** ssh  
>  ports:  
>  protocols:  
>  forward: no  
>  masquerade: no  
>  forward-ports:  
>  source-ports:  
>  icmp-blocks:  
>  rich rules:

完成設定。