dns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hostinger 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:
TypePurposeExample
AIPv4 address
192.168.1.1
AAAAIPv6 address
2001:db8::1
CNAMECanonical name alias
www.example.com.
ALIASANAME/ALIAS record
example.com.
MXMail exchange
mail.example.com.
TXTText record
v=spf1 include:...
NSName server
ns1.example.com.
SOAStart of authorityZone authority info
SRVService locator
_sip._tcp.example.com.
CAACertificate authority auth
0 issue "letsencrypt.org"
支持以下标准 DNS 记录类型:
类型用途示例
AIPv4 地址
192.168.1.1
AAAAIPv6 地址
2001:db8::1
CNAME规范名称别名
www.example.com.
ALIASANAME/ALIAS 记录
example.com.
MX邮件交换
mail.example.com.
TXT文本记录
v=spf1 include:...
NS名称服务器
ns1.example.com.
SOA权威起始区域授权信息
SRV服务定位器
_sip._tcp.example.com.
CAA证书颁发机构授权
0 issue "letsencrypt.org"

Zone Updates

区域更新

When updating DNS records, the
overwrite
flag controls behavior:
  • overwrite: true
    (default) — Replaces existing records matching name and type with the new records
  • overwrite: false
    — Updates TTL on existing records, appends new records; if no match found, creates them
更新 DNS 记录时,
overwrite
标志控制其行为:
  • overwrite: true
    (默认)— 使用新记录替换名称和类型均匹配的现有记录
  • overwrite: false
    — 更新现有记录的 TTL,追加新记录;如果未找到匹配项,则创建记录

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
14400
seconds (4 hours). Lower values propagate changes faster but increase DNS query load.
TTL 控制 DNS 解析器缓存记录的时间。默认值为
14400
秒(4 小时)。较低的值可加快更改传播,但会增加 DNS 查询负载。

Common 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
undefined
bash
undefined

Add 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" } ] } ] }'
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" } ] } ] }'

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." } ] } ] }'
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." } ] } ] }'

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" } ] } ] }'
undefined
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" } ] } ] }'
undefined

Validate Before Updating

更新前进行验证

bash
undefined
bash
undefined

Validate 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." } ] } ] }'
undefined
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." } ] } ] }'
undefined

Delete 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
undefined
bash
undefined

List available snapshots

List available snapshots

curl -X GET "https://developers.hostinger.com/api/dns/v1/snapshots/example.com"
-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"

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"
curl -X GET "https://developers.hostinger.com/api/dns/v1/snapshots/example.com/42"
-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"
undefined
curl -X POST "https://developers.hostinger.com/api/dns/v1/snapshots/example.com/42/restore"
-H "Authorization: Bearer $HOSTINGER_API_TOKEN"
undefined

API Reference

API 参考

Zone Records

区域记录

MethodEndpointDescription
GET
/api/dns/v1/zones/{domain}
Get DNS records
PUT
/api/dns/v1/zones/{domain}
Update DNS records
DELETE
/api/dns/v1/zones/{domain}
Delete DNS records
POST
/api/dns/v1/zones/{domain}/reset
Reset DNS to defaults
POST
/api/dns/v1/zones/{domain}/validate
Validate DNS records
方法端点描述
GET
/api/dns/v1/zones/{domain}
获取 DNS 记录
PUT
/api/dns/v1/zones/{domain}
更新 DNS 记录
DELETE
/api/dns/v1/zones/{domain}
删除 DNS 记录
POST
/api/dns/v1/zones/{domain}/reset
将 DNS 重置为默认设置
POST
/api/dns/v1/zones/{domain}/validate
验证 DNS 记录

Snapshots

快照

MethodEndpointDescription
GET
/api/dns/v1/snapshots/{domain}
List DNS snapshots
GET
/api/dns/v1/snapshots/{domain}/{snapshotId}
Get snapshot with contents
POST
/api/dns/v1/snapshots/{domain}/{snapshotId}/restore
Restore from snapshot
方法端点描述
GET
/api/dns/v1/snapshots/{domain}
获取 DNS 快照列表
GET
/api/dns/v1/snapshots/{domain}/{snapshotId}
获取包含内容的快照
POST
/api/dns/v1/snapshots/{domain}/{snapshotId}/restore
从快照恢复

Best Practices

最佳实践

Record Management

记录管理

  • Always validate records with the
    /validate
    endpoint before applying changes
  • Use
    overwrite: false
    when adding records without removing existing ones
  • Use
    overwrite: true
    when you want to completely replace records of a given name/type
  • 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
    whitelisted_record_types
    parameter during reset to preserve email records (MX, TXT)
  • Set
    reset_email_records: false
    when resetting if you use third-party email services
  • 进行批量更改前,请创建快照(或记下现有记录)
  • 重置时使用
    whitelisted_record_types
    参数,以保留电子邮件记录(MX、TXT)
  • 如果使用第三方电子邮件服务,重置时将
    reset_email_records
    设置为
    false

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
    dig
    or
    nslookup
    to verify:
    dig @8.8.8.8 example.com A
  • DNS 传播最长可能需要 48 小时(通常会短得多)
  • 检查旧记录的 TTL——解析器会在该时长内继续缓存
  • 使用
    dig
    或
    nslookup
    进行验证:
    dig @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
    name
    AND
    type
    — both must match
  • 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:
  • email-dns-setup.md
    — Complete email DNS setup (MX, SPF, DKIM, DMARC for Google Workspace, Microsoft 365, and Hostinger Email)
此 skill 目录中还提供以下深入指南:
  • email-dns-setup.md
    — 完整的电子邮件 DNS 设置(适用于 Google Workspace、Microsoft 365 和 Hostinger Email 的 MX、SPF、DKIM、DMARC)

References

参考资料