本文以 Debian 9 下 root 用户为例,介绍 ufw 的安装和使用。
安装
| 1 | apt update | 
查看应用列表
| 1 | ufw app list | 
启用
| 1 | ufw enable | 
查看状态
| 1 | ufw status | 
封禁一个 ip
| 1 | ufw deny from 15.15.15.51 | 
在特定 interface 上封禁:
| 1 | ufw deny in on eth0 from 15.15.15.51 | 
允许 SSH 连接(端口 22)
| 1 | ufw allow ssh | 
允许特定端口
| 1 | ufw allow 2222 | 
允许特定 ip 或子网 的连接
| 1 | ufw allow from 15.15.15.0/24 to any port 2222 | 
允许出站:
| 1 | ufw allow out 222 | 
禁止特定端口
| 1 | ufw deny 2222 | 
禁止入站:
| 1 | ufw deny in 2222 | 
删除某项规则
| 1 | ufw delete allow 2222 | 
References
How To Setup a Firewall with UFW on an Ubuntu and Debian Cloud Server
UFW Essentials: Common Firewall Rules and Commands