UFW 简单防火墙安装、配置、禁Ping
前言
UFW 是一个 Arch Linux、Debian 或 Ubuntu 中管理防火墙规则的前端,可大大简化防火墙的配置过程。
安装 UFW
如还没有安装,可以使用 apt 命令来安装
| apt-get update && apt-get install ufw | 
在使用前,你应该检查下 UFW 是否已经在运行。
| ufw status | 
如果你发现状态是 inactive ,意思是没有被激活或不起作用。
启用/禁用
| ufw enable #启用 | 
使用与配置
列出当前UFW规则
| ufw status verbose | 
添加规则
允许入站(allow)
默认情况,没有允许就是拒绝(入站),使用 ufw allow <端口> 来添加允许访问的端口或协议。
| ufw allow ssh #添加22端口 | 
拒绝访问(deny)
使用 ufw deny <端口> 来添加拒绝入站的端和协议,与添加允许的类似。
删除规则
先使用 ufw status 查看规则,再使用 ufw delete [规则] <端口> 来删除规则。
| ufw delete allow 2333/tcp | 
如果你有很多条规则,使用 numbered 参数,可以在每条规则上加个序号数字。
然后使用 ufw delete <序号> 来删除规则。
| root@p3terx:~# ufw status numbered #列出规则,并加上序号。 | 
以上都是一些简单常用的一些命令,想要深入了解,可以输入 man ufw 查看 ufw 用户手册。
禁 Ping
打开 UFW 配置文件
| vim /etc/ufw/before.rules | 
修改配置
允许 ping
| -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT | 
禁止 ping
| -A ufw-before-input -p icmp --icmp-type echo-request -j DROP | 
让配置生效
| ufw reload | 
参考资料
Debian/Ubuntu 系统中安装和配置 UFW-简单的防火墙
转载自 P3TREX
https://p3terx.com/archives/installing-and-configuring-ufw-in-debian.html
https://p3terx.com/archives/use-ufw-to-disable-icmp-protocol-access.html
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
 Comment








