Debian防火墙在云环境的应用
一 架构与原则
二 快速上手 UFW 在 Debian
sudo apt update && sudo apt install ufw -ysudo ufw allow ssh(或明确指定端口:sudo ufw allow 22/tcp)sudo ufw enable(启用前务必已放行 SSH,避免远程断开)sudo ufw allow http、sudo ufw allow httpssudo ufw allow 3306/tcpsudo ufw allow from 203.0.113.10 to any port 22 proto tcpsudo ufw allow from 192.168.1.0/24 to any port 80 proto tcpsudo ufw limit ssh(默认每分钟 6 次,可自定义:sudo ufw limit 22/tcp rate 10/minute)sudo ufw status 或 sudo ufw status numberedsudo ufw delete <rule_number> 或 sudo ufw delete allow 22/tcpsudo ufw logging on,日志路径 /var/log/ufw.log,可用 grep "UFW BLOCK" /var/log/ufw.log 过滤阻断事件。三 云上最小权限配置示例
sudo ufw default deny incoming、sudo ufw default allow outgoingsudo ufw allow http、sudo ufw allow httpssudo ufw allow from 198.51.100.0/24 to any port 22 proto tcpsudo ufw allow from 10.0.1.0/24 to any port 3306 proto tcpsudo ufw enablesudo ufw status、ss -tunlp | grep -E '(:80|:443|:22|:3306)'curl -I https://<公网IP> 或 nc -vz <公网IP> 80/443。四 故障排查与加固要点
ss -tunlp)。limit 限速规则缓解暴力破解。