firewall命令使用方法
时间: 2024-06-09 22:11:15 浏览: 13
firewall 是 Linux 系统的防火墙工具,可以用来控制入站和出站的网络流量。下面是 firewall 的一些常用命令及其使用方法:
1. 启用防火墙:`systemctl start firewalld.service`
2. 停止防火墙:`systemctl stop firewalld.service`
3. 重启防火墙:`systemctl restart firewalld.service`
4. 查看防火墙状态:`systemctl status firewalld.service`
5. 开启防火墙自启动:`systemctl enable firewalld.service`
6. 关闭防火墙自启动:`systemctl disable firewalld.service`
7. 查看已有防火墙规则:`firewall-cmd --list-all`
8. 查看所有可用服务:`firewall-cmd --get-services`
9. 开放端口:`firewall-cmd --zone=public --add-port=80/tcp --permanent` (80 为要开放的端口号,tcp 为传输协议,--permanent 参数表示永久生效)
10. 关闭端口:`firewall-cmd --zone=public --remove-port=80/tcp --permanent`
11. 添加服务:`firewall-cmd --zone=public --add-service=http --permanent` (http 为要添加的服务,--permanent 参数表示永久生效)
12. 删除服务:`firewall-cmd --zone=public --remove-service=http --permanent`
13. 允许某个 IP 访问:`firewall-cmd --zone=public --add-source=192.168.1.100 --permanent` (192.168.1.100 为要允许的 IP 地址,--permanent 参数表示永久生效)
14. 拒绝某个 IP 访问:`firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject' --permanent`
15. 重新载入防火墙规则:`firewall-cmd --reload`
注意:所有的命令都需要使用 root 用户或者具有 sudo 权限的用户执行。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)