dns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHostinger DNS
Hostinger DNS
The DNS API enables full management of DNS zone records for domains hosted on Hostinger. You can create, update, delete, validate, and reset DNS records, as well as manage DNS snapshots for backup and restore operations.
DNS API 支持对托管在 Hostinger 上的域名的 DNS 区域记录进行全面管理。您可以创建、更新、删除、验证和重置 DNS 记录,还可以管理 DNS 快照以执行备份和恢复操作。
Table of Contents
目录
Core Concepts
核心概念
DNS Records
DNS 记录
Standard DNS record types are supported:
| Type | Purpose | Example |
|---|---|---|
| A | IPv4 address | |
| AAAA | IPv6 address | |
| CNAME | Canonical name alias | |
| ALIAS | ANAME/ALIAS record | |
| MX | Mail exchange | |
| TXT | Text record | |
| NS | Name server | |
| SOA | Start of authority | Zone authority info |
| SRV | Service locator | |
| CAA | Certificate authority auth | |
支持以下标准 DNS 记录类型:
| 类型 | 用途 | 示例 |
|---|---|---|
| A | IPv4 地址 | |
| AAAA | IPv6 地址 | |
| CNAME | 规范名称别名 | |
| ALIAS | ANAME/ALIAS 记录 | |
| MX | 邮件交换 | |
| TXT | 文本记录 | |
| NS | 名称服务器 | |
| SOA | 权威起始 | 区域授权信息 |
| SRV | 服务定位器 | |
| CAA | 证书颁发机构授权 | |
Zone Updates
区域更新
When updating DNS records, the flag controls behavior:
overwrite- (default) — Replaces existing records matching name and type with the new records
overwrite: true - — Updates TTL on existing records, appends new records; if no match found, creates them
overwrite: false
更新 DNS 记录时, 标志控制其行为:
overwrite- (默认)— 使用新记录替换名称和类型均匹配的现有记录
overwrite: true - — 更新现有记录的 TTL,追加新记录;如果未找到匹配项,则创建记录
overwrite: false
Snapshots
快照
DNS snapshots capture the state of a domain's DNS zone at a point in time. Use them to restore previous configurations if something goes wrong.
DNS 快照会捕获域名 DNS 区域在某一时刻的状态。如果出现问题,可以使用快照恢复之前的配置。
TTL (Time-To-Live)
TTL(Time-To-Live,生存时间)
TTL controls how long DNS resolvers cache a record. Default is seconds (4 hours). Lower values propagate changes faster but increase DNS query load.
14400TTL 控制 DNS 解析器缓存记录的时间。默认值为 秒(4 小时)。较低的值可加快更改传播,但会增加 DNS 查询负载。
14400Common Patterns
常见模式
Get DNS Records for a Domain
获取域名的 DNS 记录
bash
curl -X GET "https://developers.hostinger.com/api/dns/v1/zones/example.com" \
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"Python SDK:
python
from hostinger_api import Hostinger
client = Hostinger(api_token="YOUR_API_TOKEN")
records = client.dns.zone.get_dns_records("example.com")
for record in records:
print(f"{record.type} {record.name} -> {record.content}")TypeScript SDK:
typescript
import { Hostinger } from "hostinger-api-sdk";
const client = new Hostinger({ apiToken: "YOUR_API_TOKEN" });
const records = await client.dns.zone.getRecords("example.com");
for (const record of records) {
console.log(`${record.type} ${record.name} -> ${record.content}`);
}PHP SDK:
php
use Hostinger\Api\HostingerApi;
$client = new HostingerApi('YOUR_API_TOKEN');
$records = $client->dns->zone->getRecords('example.com');
foreach ($records as $record) {
echo "{$record->type} {$record->name} -> {$record->content}\n";
}bash
curl -X GET "https://developers.hostinger.com/api/dns/v1/zones/example.com" \
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"Python SDK:
python
from hostinger_api import Hostinger
client = Hostinger(api_token="YOUR_API_TOKEN")
records = client.dns.zone.get_dns_records("example.com")
for record in records:
print(f"{record.type} {record.name} -> {record.content}")TypeScript SDK:
typescript
import { Hostinger } from "hostinger-api-sdk";
const client = new Hostinger({ apiToken: "YOUR_API_TOKEN" });
const records = await client.dns.zone.getRecords("example.com");
for (const record of records) {
console.log(`${record.type} ${record.name} -> ${record.content}`);
}PHP SDK:
php
use Hostinger\Api\HostingerApi;
$client = new HostingerApi('YOUR_API_TOKEN');
$records = $client->dns->zone->getRecords('example.com');
foreach ($records as $record) {
echo "{$record->type} {$record->name} -> {$record->content}\n";
}Create/Update DNS Records
创建/更新 DNS 记录
bash
undefinedbash
undefinedAdd an A record for www subdomain
Add an A record for www subdomain
curl -X PUT "https://developers.hostinger.com/api/dns/v1/zones/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "A", "ttl": 14400, "records": [ { "content": "192.168.1.1" } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "A", "ttl": 14400, "records": [ { "content": "192.168.1.1" } ] } ] }'
curl -X PUT "https://developers.hostinger.com/api/dns/v1/zones/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "A", "ttl": 14400, "records": [ { "content": "192.168.1.1" } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "A", "ttl": 14400, "records": [ { "content": "192.168.1.1" } ] } ] }'
Add MX records for email
Add MX records for email
curl -X PUT "https://developers.hostinger.com/api/dns/v1/zones/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "@", "type": "MX", "ttl": 14400, "records": [ { "content": "10 mail1.example.com." }, { "content": "20 mail2.example.com." } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "@", "type": "MX", "ttl": 14400, "records": [ { "content": "10 mail1.example.com." }, { "content": "20 mail2.example.com." } ] } ] }'
curl -X PUT "https://developers.hostinger.com/api/dns/v1/zones/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "@", "type": "MX", "ttl": 14400, "records": [ { "content": "10 mail1.example.com." }, { "content": "20 mail2.example.com." } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "@", "type": "MX", "ttl": 14400, "records": [ { "content": "10 mail1.example.com." }, { "content": "20 mail2.example.com." } ] } ] }'
Add a TXT record for SPF
Add a TXT record for SPF
curl -X PUT "https://developers.hostinger.com/api/dns/v1/zones/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": false, "zone": [ { "name": "@", "type": "TXT", "ttl": 14400, "records": [ { "content": "v=spf1 include:_spf.google.com ~all" } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": false, "zone": [ { "name": "@", "type": "TXT", "ttl": 14400, "records": [ { "content": "v=spf1 include:_spf.google.com ~all" } ] } ] }'
undefinedcurl -X PUT "https://developers.hostinger.com/api/dns/v1/zones/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": false, "zone": [ { "name": "@", "type": "TXT", "ttl": 14400, "records": [ { "content": "v=spf1 include:_spf.google.com ~all" } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": false, "zone": [ { "name": "@", "type": "TXT", "ttl": 14400, "records": [ { "content": "v=spf1 include:_spf.google.com ~all" } ] } ] }'
undefinedValidate Before Updating
更新前进行验证
bash
undefinedbash
undefinedValidate records first (returns 200 if valid, 422 if invalid)
Validate records first (returns 200 if valid, 422 if invalid)
curl -X POST "https://developers.hostinger.com/api/dns/v1/zones/example.com/validate"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "CNAME", "ttl": 14400, "records": [ { "content": "example.com." } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "CNAME", "ttl": 14400, "records": [ { "content": "example.com." } ] } ] }'
undefinedcurl -X POST "https://developers.hostinger.com/api/dns/v1/zones/example.com/validate"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "CNAME", "ttl": 14400, "records": [ { "content": "example.com." } ] } ] }'
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Content-Type: application/json"
-d '{ "overwrite": true, "zone": [ { "name": "www", "type": "CNAME", "ttl": 14400, "records": [ { "content": "example.com." } ] } ] }'
undefinedDelete Specific DNS Records
删除特定 DNS 记录
bash
curl -X DELETE "https://developers.hostinger.com/api/dns/v1/zones/example.com" \
-H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filters": [
{ "name": "www", "type": "A" },
{ "name": "old", "type": "CNAME" }
]
}'bash
curl -X DELETE "https://developers.hostinger.com/api/dns/v1/zones/example.com" \
-H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filters": [
{ "name": "www", "type": "A" },
{ "name": "old", "type": "CNAME" }
]
}'Reset DNS to Defaults
将 DNS 重置为默认设置
bash
curl -X POST "https://developers.hostinger.com/api/dns/v1/zones/example.com/reset" \
-H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"sync": true,
"reset_email_records": false,
"whitelisted_record_types": ["MX", "TXT"]
}'bash
curl -X POST "https://developers.hostinger.com/api/dns/v1/zones/example.com/reset" \
-H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"sync": true,
"reset_email_records": false,
"whitelisted_record_types": ["MX", "TXT"]
}'Work with DNS Snapshots
管理 DNS 快照
bash
undefinedbash
undefinedList available snapshots
List available snapshots
curl -X GET "https://developers.hostinger.com/api/dns/v1/snapshots/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
curl -X GET "https://developers.hostinger.com/api/dns/v1/snapshots/example.com"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
Get a specific snapshot with contents
Get a specific snapshot with contents
curl -X GET "https://developers.hostinger.com/api/dns/v1/snapshots/example.com/42"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
curl -X GET "https://developers.hostinger.com/api/dns/v1/snapshots/example.com/42"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
Restore from a snapshot
Restore from a snapshot
curl -X POST "https://developers.hostinger.com/api/dns/v1/snapshots/example.com/42/restore"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
undefinedcurl -X POST "https://developers.hostinger.com/api/dns/v1/snapshots/example.com/42/restore"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
undefinedAPI Reference
API 参考
Zone Records
区域记录
| Method | Endpoint | Description |
|---|---|---|
| | Get DNS records |
| | Update DNS records |
| | Delete DNS records |
| | Reset DNS to defaults |
| | Validate DNS records |
| 方法 | 端点 | 描述 |
|---|---|---|
| | 获取 DNS 记录 |
| | 更新 DNS 记录 |
| | 删除 DNS 记录 |
| | 将 DNS 重置为默认设置 |
| | 验证 DNS 记录 |
Snapshots
快照
| Method | Endpoint | Description |
|---|---|---|
| | List DNS snapshots |
| | Get snapshot with contents |
| | Restore from snapshot |
| 方法 | 端点 | 描述 |
|---|---|---|
| | 获取 DNS 快照列表 |
| | 获取包含内容的快照 |
| | 从快照恢复 |
Best Practices
最佳实践
Record Management
记录管理
- Always validate records with the endpoint before applying changes
/validate - Use when adding records without removing existing ones
overwrite: false - Use when you want to completely replace records of a given name/type
overwrite: true - Use as the name for root domain records
@
- 应用更改前,始终使用 端点验证记录
/validate - 添加记录而不删除现有记录时,使用
overwrite: false - 要完全替换指定名称和类型的记录时,使用
overwrite: true - 使用 作为根域名记录的名称
@
Safety
安全性
- Take a snapshot (or note existing records) before making bulk changes
- Use the parameter during reset to preserve email records (MX, TXT)
whitelisted_record_types - Set when resetting if you use third-party email services
reset_email_records: false
- 进行批量更改前,请创建快照(或记下现有记录)
- 重置时使用 参数,以保留电子邮件记录(MX、TXT)
whitelisted_record_types - 如果使用第三方电子邮件服务,重置时将 设置为
reset_email_recordsfalse
TTL
TTL
- Use lower TTL (300-600s) when planning changes for faster propagation
- Increase TTL (14400s+) for stable records to reduce DNS query load
- Remember: old cached records persist until the previous TTL expires
- 计划进行更改时,使用较低的 TTL(300–600 秒)以加快传播
- 对于稳定记录,提高 TTL(14400 秒以上)以减少 DNS 查询负载
- 请记住:旧缓存记录会持续存在,直到先前的 TTL 到期
Email Records
电子邮件记录
- Be careful with MX records — incorrect changes break email delivery
- SPF, DKIM, and DMARC records are TXT records — don't overwrite them accidentally
- 使用 MX 记录时要谨慎——错误的更改会中断电子邮件投递
- SPF、DKIM 和 DMARC 记录都是 TXT 记录——请勿意外覆盖它们
Troubleshooting
故障排查
Records Not Propagating
记录未传播
- DNS propagation can take up to 48 hours (usually much less)
- Check the TTL of the old record — resolvers cache for that duration
- Use or
digto verify:nslookupdig @8.8.8.8 example.com A
- DNS 传播最长可能需要 48 小时(通常会短得多)
- 检查旧记录的 TTL——解析器会在该时长内继续缓存
- 使用 或
dig进行验证:nslookupdig @8.8.8.8 example.com A
422 Validation Error
422 验证错误
- Invalid record content format (e.g., CNAME must end with )
. - Conflicting records (e.g., CNAME at root with other records)
- Invalid record type for the operation
- 记录内容格式无效(例如,CNAME 必须以 结尾)
. - 记录冲突(例如,根域名的 CNAME 与其他记录同时存在)
- 当前操作所用的记录类型无效
Email Stopped Working After DNS Change
DNS 更改后电子邮件停止工作
- Check MX records:
dig example.com MX - Verify SPF TXT record is intact
- Use the snapshot restore to revert if needed
- 检查 MX 记录:
dig example.com MX - 确认 SPF TXT 记录完整无误
- 如有需要,使用快照恢复功能撤销更改
Delete Not Working as Expected
删除操作未按预期工作
- Filters match by AND
name— both must matchtype - If multiple records share name/type and you want to delete only some, use the update endpoint instead
- 筛选条件按 和
name匹配——两者都必须匹配type - 如果多个记录具有相同的名称和类型,但只想删除其中一部分,请改用更新端点
See Also
另请参阅
The following deep-dive guide is available in this skill directory:
- — Complete email DNS setup (MX, SPF, DKIM, DMARC for Google Workspace, Microsoft 365, and Hostinger Email)
email-dns-setup.md
此 skill 目录中还提供以下深入指南:
- — 完整的电子邮件 DNS 设置(适用于 Google Workspace、Microsoft 365 和 Hostinger Email 的 MX、SPF、DKIM、DMARC)
email-dns-setup.md