> 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/wireguard--adding-nameserver-entries-to-client-configs.md).

# WireGuard - 为客户端配置添加名称服务器条目

以下是添加一个 **PostUp** 以及 **PostDown** 脚本到 **WireGuard** 配置文件。\
对于 **Windows**，这会添加 **PowerShell** 用于添加和删除一个的命令 **DNS 客户端规则** 当客户端连接和断开连接时。

## Windows 客户端

1. 在 **Windows** WireGuard 客户端， **编辑配置文件**.
2. 在以下位置添加以下命令 **\[Interface]** 部分：

```pwsh
PostUp = powershell -command "Add-DnsClientNrptRule -Namespace 'domainname.com' -NameServers '10.1.10.2'"
PostDown = powershell -command "Get-DnsClientNrptRule | Where { $_.Namespace -match '.*domainname\.com' } | Remove-DnsClientNrptRule -force"
```

3. 将以下条目更改为匹配 **你的** 设置：
   * **Namespace**：要添加的域名列表，以逗号分隔。
   * **NameServers**：要添加的域名服务器 IP 地址列表，以逗号分隔。

{% hint style="info" %}
**对于 -match，请确保在每个句点 (.) 前都加上反斜杠 (\\)**
{% endhint %}

***

## Linux 客户端

这可能因你的 Linux 发行版而异。

1. **编辑配置文件** 在 **Linux** 客户端。
2. 在 **\[Interface]** 部分中，添加以下内容：

```bash
PostUp = resolvectl dns %i 10.1.10.2; resolvectl domain %i domainname.com
PreUp = iptables -A INPUT -i wg -m state --state ESTABLISHED,RELATED -j ACCEPT
PreUp = iptables -A INPUT -i wg -j REJECT
PostDown = iptables -D INPUT -i wg -m state --state ESTABLISHED,RELATED -j ACCEPT
PostDown = iptables -D INPUT -i wg -j REJECT
```

3. 将 **10.1.10.2** 使用你正确的 IP 的 **域名服务器**.
4. 将 **domainname.com** 使用你的域名。

***

{% 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/wireguard--adding-nameserver-entries-to-client-configs.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.
