# nftables 安装

## 什么是 nftables

nftables 是 Linux 新一代防火墙框架，用于替代：

- iptables
- ip6tables
- ebtables

特点：

- 统一 IPv4 / IPv6
- 性能更高（内核层优化）
- 语法更现代
- 支持集合（sets）和映射（maps）



{{< steps >}}
{{< step >}}


#### 安装 nftables

```bash
apt update && apt install nftables
```

{{< /step >}}
{{< step >}}

#### 启动服务

```bash
systemctl enable nftables
systemctl start nftables
```

检查状态：

```bash
systemctl status nftables
```

{{< /step >}}
{{< step >}}

#### 确认是否接管系统

检查 nft 是否生效：

```bash
nft list ruleset
```

检查 iptables 是否仍在使用（关键）

```bash
iptables -L
```

如果你看到：

空规则 → 正常
有规则 → 可能仍在用 iptables

{{< /step >}}
{{< step >}}

#### 强制系统使用 nftables（重要）

Debian 可能使用兼容层：

```bash
update-alternatives --config iptables
```

选择：

```bash
iptables-nft
```

同样操作：

```bash
update-alternatives --config ip6tables
```

{{< /step >}}
{{< step >}}

#### 默认配置文件

```bash
/etc/nftables.conf
```

加载方式：

```bash
nft -f /etc/nftables.conf
```

{{< /step >}}
{{< /steps >}}