> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/handbook/di-17-zhang-jail-yu-rong-qi/17.9.-fu-wu-jail.md).

# 17.9.服务 jail

服务 jail 从 FreeBSD 15.0 开始可用。

服务 jail 完全通过 **/etc/rc.conf** 或 [sysrc(8)](https://man.freebsd.org/cgi/man.cgi?query=sysrc\&sektion=8\&format=html) 配置。基本系统服务支持服务 jail。它们包含一行配置，启用网络连接或解除其他 jail 限制。不适合在 jail 中运行的基本系统服务，即使在 **/etc/rc.conf** 中启用，也配置为不作为服务 jail 启动。此类服务的例子包括在启动或停止方法中挂载或卸载某些内容的服务，或者仅配置诸如路由、防火墙等内容的服务。

第三方服务可能支持服务 jail，也可能不支持。要检查某个服务是否支持服务 jail，可使用以下命令：

```sh
# grep _svcj_options /path/to/rc.d/servicename
```

如果没有输出，表示该服务不支持服务 jail，或者不需要任何额外的权限（例如，网络访问）。

如果服务不支持服务 jail，并且需要网络访问，可通过向 **/etc/rc.conf** 添加必要的配置来使其支持：

```sh
# sysrc servicename_svcj_options=net_basic
```

有关所有可能的 `_svcj_options`，请参阅 [rc.conf(5)](https://man.freebsd.org/cgi/man.cgi?query=rc.conf\&sektion=5\&format=html) 手册页。

要为某个服务启用服务 jail，需要先停止该服务，然后将 `servicename_svcj` 变量设置为 YES。以将 [syslogd(8)](https://man.freebsd.org/cgi/man.cgi?query=syslogd\&sektion=8\&format=html) 放入服务 jail 为例，执行以下命令：

```sh
# service syslogd stop
# sysrc syslogd_svcj=YES
# service syslogd start
```

如果更改了 `servicename_svcj` 变量，必须在更改之前停止该服务。如果服务没有停止，rc 框架将无法检测到服务的正确状态，并且无法执行所请求的操作。

服务 jail 仅通过 [rc.conf(5)](https://man.freebsd.org/cgi/man.cgi?query=rc.conf\&sektion=5\&format=html)/[sysrc(8)](https://man.freebsd.org/cgi/man.cgi?query=sysrc\&sektion=8\&format=html) 和 [service(8)](https://man.freebsd.org/cgi/man.cgi?query=service\&sektion=8\&format=html) 命令管理。可使用 jail 工具（如 [jls(8)](https://man.freebsd.org/cgi/man.cgi?query=jls\&sektion=8\&format=html)，在 [管理 jail](/handbook/di-17-zhang-jail-yu-rong-qi/17.10.-guan-li-jail.md) 中有说明）来检查服务的运行情况，但不应使用 [jail(8)](https://man.freebsd.org/cgi/man.cgi?query=jail\&sektion=8\&format=html) 命令来管理它们。


---

# 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://book.bsdcn.org/handbook/di-17-zhang-jail-yu-rong-qi/17.9.-fu-wu-jail.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.
