简易防火墙

来自 Alpine Linux
(重定向自 UFW)

UFW 是 Uncomplicated Firewall 的缩写,是一个用于管理 netfilter 防火墙的程序。它提供命令行界面,旨在简单易用。

安装

UFW 可以在 community 仓库中找到。阅读 Alpine_Linux_package_management#Repository_pinning 以启用 community 仓库。

一旦 community 仓库被启用,就可以通过执行以下命令安装 UFW

apk add ip6tables ufw

基本配置

以下是一个简单的配置,默认情况下将拒绝所有传入和传出的数据通信,并允许传入的 SSH、传出的 DNS 和 NTP 流量

ufw default deny incoming
ufw default deny outgoing
ufw limit SSH         # open SSH port and protect against brute-force login attacks
ufw allow out 123/udp # allow outgoing NTP (Network Time Protocol)

# The following instructions will allow apk to work:
ufw allow out DNS     # allow outgoing DNS
ufw allow out 80/tcp  # allow outgoing HTTP traffic

以下行仅在您首次安装软件包时需要

ufw enable # 启用防火墙 rc-update add ufw # 添加 UFW 初始化脚本

检查 UFW 的状态

ufw status

无盘模式

如果您已将 Alpine Linux 安装为无盘模式,则需要使用 Alpine Local Backup (lbu) 来保存您的 UFW 配置。UFW 数据存储在 /usr/lib/ufw 中,因此请使用以下命令来保存 UFW 配置

lbu add /usr/lib/ufw lbu commit

参见

  • nftables:执行实际过滤的内核子系统及其用户空间实用程序。