> 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 máy khách

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 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/vi/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.
