在使用Debian系统的iptables进行网络配置和安全管理时,用户常常会遇到一些常见问题。以下是针对这些问题的解决方案:
SSH无法远程连接
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -P INPUT DROP
服务器总被Ping洪水攻击
iptables -A INPUT -p icmp --icmp-type 8 -m limit --limit 5/s -j ACCEPT
iptables -A INPUT -p icmp -j LOG --log-prefix "ICMP_Attack: "
iptables -A INPUT -p icmp -j DROP
网站端口无法访问
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to 192.168.1.100:80
规则在重启后丢失
iptables-save > /etc/iptables.rules
保存规则。iptables-restore < /etc/iptables.rules
在启动时加载规则。快速封禁恶意IP
ipset create blacklist hash:ip timeout 86400
iptables -A INPUT -m set --match-set blacklist src -j DROP
为了确保iptables规则在系统重启后依然有效,需要进行规则的持久化。可以使用以下命令:
iptables-persistent
包:sudo apt-get install iptables-persistent
sudo iptables-save /etc/iptables/rules.v4
/etc/network/if-pre-up.d/iptables
文件,使其在网卡设备准备启动的阶段执行保存规则的命令。通过以上步骤,可以有效解决Debian系统中使用iptables时遇到的一些常见问题,并确保防火墙规则的持久化。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Debian PHP如何解决常见问题