# 自建DDNS說明-Dynu.com

## 由於網路安全原因，我們停止了免費域名（DDNS）的解析，但用戶仍然可以通過自建DDNS獲取伺服器的外網IP。

## 下面我們將使用dynu.com的免費DDNS服務，建立您的DDNS。(dynu.com需要科學上網)

#### 1. 打開下方鏈接登記您的帳戶

<https://www.dynu.com/zh-CN/>

然後進入「後台控制中心」

![](https://1362237260-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lp3R2LXmnVtjgBxeIHC%2F-M-_S6SLtc4yi9ND3ndF%2F-M-_SYLTfpEoO9pI6r63%2FJietu20200208-234051.jpg?alt=media\&token=19626a17-9d0f-4a49-a71b-ce48ebc67e03)

![](https://1362237260-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lp3R2LXmnVtjgBxeIHC%2F-M-_Lcq6bERK_Pq9F1OS%2F-M-_MrZHnu3k5pb9kMJu%2FJietu20200208-231607.jpg?alt=media\&token=098993b2-e81b-4329-8022-37e9431cd764)

![](https://1362237260-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lp3R2LXmnVtjgBxeIHC%2F-M-_Lcq6bERK_Pq9F1OS%2F-M-_NKcqyLL16bpQtXPq%2FJietu20200208-231810.jpg?alt=media\&token=80070426-6753-45b8-8a40-54f778fd46b0)

![](https://1362237260-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lp3R2LXmnVtjgBxeIHC%2F-M-_Lcq6bERK_Pq9F1OS%2F-M-_O6jctJHdOf2G-xBY%2FJietu20200208-232133.jpg?alt=media\&token=df159747-cb82-4bb3-ab84-a23256251c17)

![](https://1362237260-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lp3R2LXmnVtjgBxeIHC%2F-M-_Lcq6bERK_Pq9F1OS%2F-M-_OqlaG0brngnKC62I%2FJietu20200208-232451.jpg?alt=media\&token=dc63357c-86a0-46e9-8f49-151f0bbbccec)

#### 2. 使用腳本讓VPS自動更新DDNS

登入您的VPS終端，執行下列命令

```bash
##Debian/Ubuntu
apt-get update
apt-get install curl -y

##CentOS
yum update -y
yum install curl -y
```

{% hint style="warning" %}
使用CURL提交測試，注意修改您的信息

hostname=您申請的域名

password=您Dynu帳戶的密碼
{% endhint %}

```bash
curl -4 "https://api.dynu.com/nic/update?hostname=您申請的域名&password=您Dynu帳戶的密碼"

## 返回下面信息表示成功 ##
good xxx.xxx.xxx.xxx (IP地址)
```

設定定時更新

```bash
crontab -e
```

按`i`进入编辑模式，貼上下方命令，並按`esc`一下，再输入`:wq`再回車保存

```bash
*/1 * * * * curl -4 "https://api.dynu.com/nic/update?hostname=您申請的域名&password=您Dynu帳戶的密碼" >/dev/null 2>&1
```

{% hint style="success" %}
至此所有步驟完成，當IP變更時腳本會自動更新A紀錄指向您的域名

您可以登入dynu.com後台查看域名IP

並可以使用您的DDNS連接您的VPS
{% endhint %}

{% hint style="info" %}
需要注意的是DDNS生效時間存在地區差異，請耐心等待DNS更新。
{% endhint %}


---

# Agent Instructions: 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:

```
GET https://doc.anyhk.net/anyhk/ddns/ddns-dynu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
