# 33.1.概述

防火墙使得过滤进出系统的流量成为可能。防火墙可以使用一个或多个“规则”集来检查网络数据包，当它们进入或离开网络连接时，防火墙会决定是允许流量通过还是阻止它。防火墙的规则可以检查数据包的一个或多个特征，如协议类型、源地址或目标地址、源 Port 或目标端口。

防火墙可以增强主机或网络的安全性。它们可以用于执行以下一项或多项操作：

* 保护并隔离内部网络的应用程序、服务和机器免受来自公共互联网的不良流量。
* 限制或禁用内部网络的主机访问公共互联网服务。
* 支持网络地址转换（NAT），使内部网络可以使用私有 IP 地址，并通过单一 IP 地址或共享池的公共地址与公共互联网共享单一连接。

FreeBSD 内置了三种防火墙：PF、IPFW 和 IPFILTER，也称为 IPF。FreeBSD 还提供了两种流量整形工具，用于控制带宽使用：[altq(4)](https://man.freebsd.org/cgi/man.cgi?query=altq\&sektion=4\&format=html) 和 [dummynet(4)](https://man.freebsd.org/cgi/man.cgi?query=dummynet\&sektion=4\&format=html)。ALTQ 通常与 PF 紧密关联，而 dummynet 与 IPFW 紧密关联。每个防火墙使用规则来控制数据包的访问，无论它们是进出 FreeBSD 系统，它们的方法不同，并且每种防火墙都有不同的规则语法。

FreeBSD 提供了多种防火墙，以满足不同用户的需求和偏好。每个用户应评估哪种防火墙最能满足他们的需求。

阅读本章后，你将了解：

* 如何定义数据包过滤规则。
* FreeBSD 内置的防火墙之间的区别。
* 如何使用和配置 PF 防火墙。
* 如何使用和配置 IPFW 防火墙。
* 如何使用和配置 IPFILTER 防火墙。

在阅读本章之前，你应该：

* 理解基本的 FreeBSD 和互联网概念。

> **注意**
>
> 由于所有防火墙都是基于检查所选数据包控制字段的值，因此防火墙规则集的创建者必须了解 TCP/IP 的工作原理，数据包控制字段中不同值的含义，以及这些值如何在正常会话中使用。有关详细介绍，请参阅 [Daryl’s TCP/IP Primer](http://www.ipprimer.com/)。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/hanbook/di-33-zhang-fang-huo-qiang/33.1.-gai-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
