在Debian系统中设置防火墙规则可以通过多种工具实现,其中最常用的是ufw
和iptables
。以下是使用这两种工具设置防火墙规则的详细步骤:
sudo apt update
sudo apt install ufw
sudo ufw status verbose
sudo ufw default allow outgoing # 设置默认允许出站连接
sudo ufw default deny incoming # 设置默认拒绝入站连接
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw allow 8080/tcp
sudo ufw enable
sudo ufw status
sudo apt update
sudo apt install iptables
sudo iptables -L -n -v
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables-save /etc/iptables/rules.v4
sudo systemctl enable iptables
sudo systemctl start iptables
sudo systemctl restart netfilter-persistent