阅读量:2
在Debian系统中,常用ufw或iptables配置防火墙,以下是具体方法:
使用ufw(推荐,简单易用)
-
安装ufw
sudo apt update && sudo apt install ufw -
启用ufw
sudo ufw enable -
配置规则
- 允许端口(如HTTP/HTTPS):
sudo ufw allow 80/tcp # HTTP sudo ufw allow 443/tcp # HTTPS - 拒绝端口(如FTP):
sudo ufw deny 21/tcp - 允许特定IP访问:
sudo ufw allow from 192.168.1.100 to any port 22
- 允许端口(如HTTP/HTTPS):
-
查看状态
sudo ufw status -
保存规则(自动生效,无需手动保存)
使用iptables(底层工具,需手动配置)
-
安装iptables
sudo apt update && sudo apt install iptables -
配置规则
- 允许SSH:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT - 拒绝其他入站流量:
sudo iptables -P INPUT DROP sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- 允许SSH:
-
保存规则
sudo iptables-save > /etc/iptables/rules.v4 -
设置开机自启
创建服务文件/etc/systemd/system/iptables-restore.service,内容如下:[Unit] Description=Restore IPTables rules Before=network.target [Service] Type=oneshot ExecStart=/sbin/iptables-restore < /etc/iptables/rules.v4 [Install] WantedBy=multi-user.target然后执行:
sudo systemctl enable iptables-restore.service sudo systemctl start iptables-restore.service
注意事项
ufw基于iptables,适合新手;iptables需手动编写规则,适合高级用户。- 操作前建议备份规则,避免误配置导致网络中断。
- 远程服务器配置时,确保保留SSH访问权限。
以上就是关于“Debian Context里如何设置防火墙”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm