问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

Debian 11防火墙配置指南:守护你的网络安全

创作时间:
作者:
@小白创作中心

Debian 11防火墙配置指南:守护你的网络安全

引用
CSDN
15
来源
1.
https://blog.csdn.net/yygydjkthh/article/details/50772238
2.
https://blog.csdn.net/qq_21439971/article/details/51524727
3.
https://devpress.csdn.net/linux/62e78fa0a254c06d462e2a8a.html
4.
https://wiki.debian.org/nftables
5.
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-debian
6.
https://www.cnblogs.com/dannylinux/p/10275339.html
7.
https://blog.dreamtobe.cn/maintain_debian/
8.
https://my.oschina.net/emacs_8817348/blog/17334746
9.
https://wiki.debian.org/nftables#Reverting_to_legacy_xtables
10.
https://wiki.debian.org/nftables#Use_firewalld
11.
https://vegastack.com/tutorials/install-and-configure-ufw-firewall-on-debian-11-bullseye/
12.
https://computingforgeeks.com/how-to-install-and-configure-firewalld-on-debian/
13.
https://www.koogua.com/article/166
14.
https://learn.microsoft.com/zh-cn/previous-versions/windows/desktop/ics/windows-firewall-advanced-security-start-page
15.
https://my.oschina.net/emacs_8817372/blog/17334804

在当今数字化时代,网络安全已成为每个系统管理员和开发者必须面对的重要课题。作为Linux世界中广受欢迎的发行版之一,Debian 11提供了强大的防火墙功能,可以帮助用户构建安全的网络环境。本文将详细介绍如何在Debian 11上配置防火墙,以保护服务器免受恶意攻击。

01

Debian 11的默认防火墙工具:nftables

自Debian 10 Buster版本开始,nftables已成为默认的防火墙框架。nftables由Netfilter项目开发,提供了包过滤、网络地址转换(NAT)和其他包处理功能。它取代了传统的iptables工具,成为更高效、更灵活的防火墙解决方案。

要检查nftables的状态,可以使用以下命令:

sudo nft list ruleset

如果输出为空,表示当前没有配置任何规则。要配置基本的防火墙规则,可以使用以下示例:

sudo nft add table inet filter
sudo nft add chain inet filter input { type filter hook input priority 0 \; }
sudo nft add chain inet filter forward { type filter hook forward priority 0 \; }
sudo nft add chain inet filter output { type filter hook output priority 0 \; }
sudo nft add rule inet filter input ct state established,related accept
sudo nft add rule inet filter input iif lo accept
sudo nft add rule inet filter input tcp dport 22 accept
sudo nft add rule inet filter input drop

这些命令创建了一个基本的防火墙规则集,允许SSH连接并拒绝其他所有入站流量。

02

使用UFW简化防火墙管理

对于不熟悉底层包过滤技术的用户,Uncomplicated Firewall(UFW)提供了一个更简单的防火墙管理界面。UFW隐藏了iptables和nftables的复杂性,使用户能够快速配置基本的防火墙规则。

要安装UFW,可以使用以下命令:

sudo apt install ufw

安装完成后,可以使用以下命令启用UFW:

sudo ufw enable

要允许特定服务(如SSH、HTTP等),可以使用以下命令:

sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https

要查看当前的防火墙状态和规则,可以使用:

sudo ufw status verbose
03

高级配置和最佳实践

为了进一步提高系统的安全性,可以采取以下最佳实践:

  1. 设置默认策略:将默认策略设置为拒绝所有入站流量,只允许必要的服务。
sudo ufw default deny incoming
sudo ufw default allow outgoing
  1. 使用SSH密钥认证:禁用密码登录,只允许使用SSH密钥认证。

编辑/etc/ssh/sshd_config文件,将以下行更改为:

PasswordAuthentication no
PubkeyAuthentication yes

然后重启SSH服务:

sudo systemctl restart ssh
  1. 禁用不必要的服务:只运行需要的服务,关闭所有不必要的服务。

使用systemctl命令检查和管理服务:

sudo systemctl list-units --type=service
sudo systemctl stop <service_name>
sudo systemctl disable <service_name>
  1. 定期更新系统:确保系统和所有软件包都是最新版本,及时应用安全补丁。
sudo apt update
sudo apt upgrade

通过遵循这些最佳实践,可以显著提高Debian 11系统的安全性。防火墙是保护服务器免受恶意攻击的第一道防线,正确配置防火墙对于维护网络安全至关重要。无论是使用nftables还是UFW,都应该根据实际需求制定合适的防火墙策略,并定期检查和更新规则,以应对不断变化的威胁环境。

© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号