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

# Wireguard - Thêm mục nameserver vào cấu hình client

Cách thêm các script PostUp và PostDown vào cấu hình client WireGuard để phân giải DNS nameserver trên Windows và Linux.

Sau đây là các hướng dẫn để thêm một **PostUp** và **PostDown** script vào tệp **Wireguard** cấu hình.\
Đối với **Windows**, điều này sẽ thêm **PowerShell** các lệnh để thêm và xóa một **Quy tắc DNS Client** khi máy khách kết nối và ngắt kết nối.

## Máy khách Windows

1. Trong **Windows** máy khách WireGuard, **chỉnh sửa tệp cấu hình**.
2. Thêm các lệnh sau vào **\[Interface]** phần:

```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. Hãy thay đổi các mục sau cho khớp **với** thiết lập của bạn:
   * **Namespace**: Một danh sách tên miền, phân tách bằng dấu phẩy, để thêm.
   * **NameServers**: Một danh sách địa chỉ IP của máy chủ tên miền, phân tách bằng dấu phẩy.

{% hint style="info" %}
**Với -match, hãy chắc chắn bao gồm một dấu gạch chéo ngược (\\) trước mỗi dấu chấm (.)**
{% endhint %}

***

## Máy khách Linux

Điều này có thể khác nhau tùy theo bản phân phối Linux của bạn.

1. **Chỉnh sửa tệp cấu hình** trên **Linux** máy khách.
2. Trong **\[Interface]** phần, hãy thêm như sau:

```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. Thay thế **10.1.10.2** với IP chính xác của **máy chủ DNS**.
4. Thay thế **domainname.com** với tên miền của bạn.

***

{% hint style="info" %}
**Thông tin tài liệu**

* Cập nhật lần cuối: 2024-08-29
* Phiên bản 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.verge.io/knowledge-base/vi/networking/wireguard--adding-nameserver-entries-to-client-configs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
