在Debian系统中,可以使用iptables或firewalld来配置防火墙规则。以下是使用iptables和firewalld自定义规则的方法:
sudo apt-get update
sudo apt-get install iptables
sudo vim /etc/iptables.rules
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables-save > /etc/iptables.rules
sudo iptables-restore < /etc/iptables.rules
sudo cp /etc/network/if-pre-up.d/iptables /etc/network/if-pre-up.d/iptables.disabled
sudo chmod +x /etc/network/if-pre-up.d/iptables
sudo apt-get update
sudo apt-get install firewalld
sudo systemctl start firewalld
sudo firewall-cmd --set-default-zone=public
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports
sudo systemctl enable firewalld
在使用iptables或firewalld配置防火墙规则时,请根据实际需求调整规则,并确保规则不会影响到系统的正常运作。对于复杂的规则配置,建议在测试环境中先行验证。