> For the complete documentation index, see [llms.txt](https://docs.verge.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verge.io/knowledge-base/zh/networking/running-a-pfsense-virtual-firewall.md).

# 最佳实践 - 运行 pfSense 虚拟防火墙

pfSense 是一款广泛使用的开源防火墙和路由器软件，可以作为虚拟机（VM）在 VergeOS 中运行。在 VergeOS 中使用 pfSense 可以实现高度可定制且灵活的防火墙配置。以下是在 VergeOS 中创建和维护 pfSense 虚拟防火墙的最佳实践。

## 1. 配置磁盘和网络接口

将 pfSense 作为虚拟机部署时，请确保磁盘和网络接口已配置为获得最佳性能。

* **磁盘和网络接口类型**：将磁盘和网络接口都设置为 **VirtIO**。与默认选项相比，这种配置可提供更好的性能。
  * **网卡使用 VirtIO**：默认情况下，VergeOS 可能会将网络接口配置为使用 **E1000**。虽然这样也能工作，但建议切换到 **VirtIO** 以获得更高的吞吐量并减少 CPU 开销。不使用 VirtIO 可能会导致间歇性的流量问题或速度变慢，尤其是在高网络负载下。
  * **存储使用 VirtIO**：使用 VirtIO 作为存储接口可确保更快的磁盘 I/O，在处理大型防火墙日志或管理有状态连接时减少系统瓶颈。

## 2. 禁用硬件校验和卸载

在某些环境中，pfSense 可能会遇到网络性能问题，例如丢包、速度变慢或连接超时。这通常是由于虚拟化网卡上的硬件校验和卸载所致。

* **禁用硬件校验和卸载**:

  * 在 pfSense 界面中，导航到 **系统** > **高级** > **网络** 并禁用 **硬件校验和卸载**.
  * 启用后，pfSense 会将校验和的处理卸载到虚拟网卡。不过，此功能更适合物理网卡；在虚拟化环境中，它可能会在虚拟机上产生不必要的处理开销，从而导致性能下降。

  ![pfSense 网卡卸载设置](/files/e0defc063e5b2a843ddea5babe241260d7be1fd6)

## 3. 分配足够的资源

* **CPU 和 RAM 分配**:
  * 根据网络规模和防火墙规则的复杂程度，请确保为您的 **CPU 核心** 以及 **RAM** 分配充足的资源给 pfSense 虚拟机。
  * 对于中小型环境，通常 2 个 CPU 核心和 2GB RAM 就足够了。对于更复杂的配置或更高的网络流量，建议增加这些资源，以确保最佳性能。
* **磁盘空间**
  * 请分配足够的磁盘空间用于系统日志、缓存和配置备份。至少先分配 **10GB** 磁盘空间，并根据所使用的功能进行增加，例如 VPN 或 IPS/IDS 日志记录。

## 4. 快照和回滚

* **使用 VergeOS 快照**:
  * 在对 pfSense 配置进行重大更改或执行大型升级之前，请为 pfSense 虚拟机创建一个 VergeOS 快照。这样在配置错误或发生故障时可以快速回滚。
* **自动化快照**:
  * 为 pfSense 的快照自动化，以确保定期备份防火墙状态。这些快照可以在 VergeOS 中计划执行，并在需要时轻松恢复。

***

遵循这些最佳实践可确保 pfSense 在 VergeOS 中高效且安全地运行，为您的虚拟化网络环境提供可靠且高性能的防火墙解决方案。

***

{% hint style="info" %}
**文档信息**

* 最后更新：2024-08-29
* vergeOS 版本：4.12.6
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.verge.io/knowledge-base/zh/networking/running-a-pfsense-virtual-firewall.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
