如何查看ufw专属日志?
美国、香港服务器
如何查看ufw专属日志?
06-03 来源:
Ubuntu20 UFW 专属日志全查看(日志文件:/var/log/ufw.log)
1、实时动态查看(最常用)
bash
运行
# 实时整份日志
tail -f /var/log/ufw.log
# 只看【被拦截】流量(UFW BLOCK,黑客扫描、爆破全在这)
tail -f /var/log/ufw.log | grep "UFW BLOCK"
# 只看【放行】流量(UFW ALLOW)
tail -f /var/log/ufw.log | grep "UFW ALLOW"
2、筛选指定端口 / IP
bash
运行
# 筛选SSH 22端口拦截记录
grep "DPT=22" /var/log/ufw.log | grep BLOCK
# 筛选某个源IP所有访问记录 SRC=源IP
grep "SRC=185.xxx.xxx.xxx" /var/log/ufw.log
3、统计爆破高频 IP(封禁用)
bash
运行
awk "/UFW BLOCK/ {print $12}" /var/log/ufw.log | sort | uniq -c | sort -nr | head -20
输出格式:次数 IP,次数几百就是扫描 IP,ufw deny from x.x.x.x拉黑。
4、查看历史压缩日志
日志自动轮替压缩:ufw.log.1、ufw.log.2.gz
bash
运行
# 读取压缩日志
zcat /var/log/ufw.log.2.gz | grep BLOCK
5、确认日志是否正常开启
bash
运行
ufw status verbose
看到 Logging: on (medium) 代表日志开启。
low:简略;medium(推荐):放行 + 拦截全记录;full:全量数据包(耗硬盘)
6、日志字段简单释义
plaintext
SRC=源IP DST=本机IP DPT=目标端口 PROTO=TCP/UDP
UFW BLOCK = 防火墙丢弃
UFW ALLOW = 防火墙放行
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快