You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.1 KiB
116 lines
2.1 KiB
3 years ago
|
## 安装
|
||
|
|
||
|
```shell
|
||
|
yum install firewalld
|
||
|
```
|
||
|
|
||
|
## 基本使用
|
||
|
|
||
|
使用`systemctl `管理程序状态
|
||
|
|
||
|
## 配置
|
||
|
|
||
|
- 查看帮助、版本、状态
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --help
|
||
|
firewall-cmd --version
|
||
|
firewall-cmd --state
|
||
|
```
|
||
|
|
||
|
- 查看所有打开的端口
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=public --list-ports
|
||
|
```
|
||
|
|
||
|
- 更新防火墙规则、更新并重启
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --reload
|
||
|
firewall-cmd --completely-reload
|
||
|
```
|
||
|
|
||
|
- 查看已激活的Zone信息
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --get-active-zones
|
||
|
```
|
||
|
|
||
|
- 查看指定接口所属区域
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --get-zone-of-interface=eth0
|
||
|
```
|
||
|
|
||
|
- 拒绝所有包、取消拒绝状态、查看是否拒绝
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --panic-on
|
||
|
firewall-cmd --panic-off
|
||
|
firewall-cmd --query-panic
|
||
|
```
|
||
|
|
||
|
## 开启和关闭端口
|
||
|
|
||
|
以下都是指在public的zone下的操作,不同的Zone只要改变Zone后面的值就可以
|
||
|
|
||
|
- 添加
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=public --add-port=80/tcp --permanent
|
||
|
```
|
||
|
|
||
|
--permanent永久生效,没有此参数重启后失效
|
||
|
|
||
|
- 查看
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=public --query-port=80/tcp
|
||
|
```
|
||
|
|
||
|
- 删除
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=public --remove-port=80/tcp --permanent
|
||
|
```
|
||
|
|
||
|
## 管理服务
|
||
|
|
||
|
以smtp服务为例, 添加到work zone,添加、查看、删除
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=work --add-service=smtp
|
||
|
firewall-cmd --zone=work --query-service=smtp
|
||
|
firewall-cmd --zone=work --remove-service=smtp
|
||
|
```
|
||
|
|
||
|
## 配置 IP 地址伪装
|
||
|
|
||
|
查看、打开、关闭
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=external --query-masquerade
|
||
|
firewall-cmd --zone=external --add-masquerade
|
||
|
firewall-cmd --zone=external --remove-masquerade
|
||
|
```
|
||
|
|
||
|
## 端口转发
|
||
|
|
||
|
- `tcp`相同IP不同端口转发
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=external --add-forward-port=22:porto=tcp:toport=3753
|
||
|
```
|
||
|
|
||
|
- `tcp`不同IP相同端口转发
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=external --add-forward-port=22:porto=tcp:toaddr=192.168.1.112
|
||
|
```
|
||
|
|
||
|
- `tcp`同不IP不同端口转发
|
||
|
|
||
|
```shell
|
||
|
firewall-cmd --zone=external --add-forward-port=22:porto=tcp::toport=3753:toaddr=192.168.1.112
|
||
|
```
|