Debian防火墙(如UFW、iptables)可通过以下方式与其他服务配合:
服务端口配置
sudo ufw allow ssh # 基于服务名配置
sudo ufw allow 80/tcp # 基于端口号配置
sudo ufw allow from 192.168.1.0/24 to any port 3306 # MySQL默认端口
与日志服务集成
sudo ufw logging on # UFW日志
sudo iptables -A INPUT -j LOG --log-prefix "iptables-dropped: " # iptables日志
/var/log/ufw.log)监控异常流量,辅助安全审计。与其他安全工具联动
sudo apt install fail2ban
# 编辑/etc/fail2ban/jail.local,启用SSH防护并关联UFW
[sshd]
enabled = true
port = ssh
banaction = ufw
网络接口与转发规则
sudo ufw deny in on eth1 from any to any port 22
sudo ufw allow in on eth0 from any to any port 22
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j DNAT --to-destination 云服务IP:80
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
注意:修改规则前需确保不影响现有服务,建议先测试规则有效性,避免误配置导致服务中断。