tencentcloud-dns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDNSPod (Tencent Cloud DNS)
DNSPod(腾讯云DNS)
Manage DNS records via the DNSPod API.
Setup: See tencentcloud authentication. DNSPod uses the same Tencent Cloud SecretId / SecretKey as the rest of the platform — there's no separate/DP_Idfor the v3 API. The SDK client below auto-readsDP_Key/TENCENTCLOUD_SECRET_IDfrom env.TENCENTCLOUD_SECRET_KEYThe legacy v2 DNSPod API used a different key format; this skill targets the v3 SDK exclusively.
通过DNSPod API管理DNS记录。
配置说明: 请查看腾讯云认证。DNSPod使用与腾讯云其他服务相同的SecretId/SecretKey——v3 API没有单独的/DP_Id。下方的SDK客户端会自动从环境变量中读取DP_Key/TENCENTCLOUD_SECRET_ID。TENCENTCLOUD_SECRET_KEY旧版v2 DNSPod API使用不同的密钥格式;本技能仅针对v3 SDK。
CLI (preferred)
CLI(推荐方式)
The skill ships — wraps every common DNSPod v3 operation.
scripts/dns.pybash
DNS=$SKILL_DIR/scripts/dns.py
python3 $DNS domains # list domains
python3 $DNS list example.com # records on one domain
python3 $DNS list example.com --type CNAME # filter by type
python3 $DNS search example.com --keyword api # client-side keyword search
python3 $DNS create example.com --sub www --type A --value 1.2.3.4
python3 $DNS create example.com --sub @ --type MX --value 'mail.example.com.' --mx 10
python3 $DNS create example.com --sub _acme-challenge --type TXT --value '"<token>"'
python3 $DNS update example.com <record-id> --sub www --type A --value 5.6.7.8
python3 $DNS delete example.com <record-id> --yes # destructive, requires --yesThe subcommand requires — without it, it prints a dry-run line so you can confirm the right first.
delete--yesrecord-id本技能附带脚本——封装了所有常见的DNSPod v3操作。
scripts/dns.pybash
DNS=$SKILL_DIR/scripts/dns.py
python3 $DNS domains # 列出所有域名
python3 $DNS list example.com # 列出单个域名的记录
python3 $DNS list example.com --type CNAME # 按类型筛选记录
python3 $DNS search example.com --keyword api # 客户端侧关键词搜索
python3 $DNS create example.com --sub www --type A --value 1.2.3.4
python3 $DNS create example.com --sub @ --type MX --value 'mail.example.com.' --mx 10
python3 $DNS create example.com --sub _acme-challenge --type TXT --value '"<token>"'
python3 $DNS update example.com <record-id> --sub www --type A --value 5.6.7.8
python3 $DNS delete example.com <record-id> --yes # 破坏性操作,需添加--yes参数delete--yesrecord-idWhen to Use
使用场景
- Add a new subdomain (A / AAAA / CNAME)
- Update an existing record (change IP, change CNAME target)
- Add email-related records (MX, SPF / DKIM / DMARC TXT)
- Add domain-verification TXT records (Google / Search Console / SSL ACME challenges)
- List or search records on a domain
- Delete obsolete records
- 添加新子域名(A/AAAA/CNAME记录)
- 更新现有记录(修改IP地址、CNAME目标)
- 添加邮件相关记录(MX、SPF/DKIM/DMARC TXT记录)
- 添加域名验证TXT记录(Google/搜索控制台/SSL ACME挑战)
- 列出或搜索域名下的记录
- 删除废弃记录
Dependencies
依赖安装
bash
pip install tencentcloud-sdk-pythonbash
pip install tencentcloud-sdk-pythonQuick start
快速开始
python
import os
from tencentcloud.common import credential
from tencentcloud.dnspod.v20210323 import dnspod_client, models
cred = credential.EnvironmentVariableCredential().get_credential()python
import os
from tencentcloud.common import credential
from tencentcloud.dnspod.v20210323 import dnspod_client, models
cred = credential.EnvironmentVariableCredential().get_credential()DNSPod is global — region is ignored, but the SDK still requires one.
DNSPod为全局服务——区域参数会被忽略,但SDK仍要求传入该参数。
client = dnspod_client.DnspodClient(cred, "")
undefinedclient = dnspod_client.DnspodClient(cred, "")
undefinedWorkflows
工作流示例
List domains in the account
列出账号下的所有域名
python
req = models.DescribeDomainListRequest()
req.Limit = 100
resp = client.DescribeDomainList(req)
for d in resp.DomainList:
print(d.DomainId, d.Name, d.Status, d.RecordCount)python
req = models.DescribeDomainListRequest()
req.Limit = 100
resp = client.DescribeDomainList(req)
for d in resp.DomainList:
print(d.DomainId, d.Name, d.Status, d.RecordCount)List records for a domain
列出单个域名的记录
python
req = models.DescribeRecordListRequest()
req.Domain = "example.com"
req.Limit = 100 # max 3000python
req = models.DescribeRecordListRequest()
req.Domain = "example.com"
req.Limit = 100 # 最大支持3000Optional: req.RecordType = "A"
可选:req.RecordType = "A"
Optional: req.Subdomain = "api"
可选:req.Subdomain = "api"
resp = client.DescribeRecordList(req)
for r in resp.RecordList:
print(r.RecordId, r.Name, r.Type, r.Value, "TTL=", r.TTL, "Line=", r.Line)
undefinedresp = client.DescribeRecordList(req)
for r in resp.RecordList:
print(r.RecordId, r.Name, r.Type, r.Value, "TTL=", r.TTL, "Line=", r.Line)
undefinedSearch by keyword (filter client-side)
关键词搜索(客户端侧过滤)
python
req = models.DescribeRecordListRequest()
req.Domain = "example.com"
req.Limit = 3000
resp = client.DescribeRecordList(req)
matches = [r for r in resp.RecordList if "api" in r.Name or "api" in r.Value]
for r in matches:
print(r.RecordId, r.Name, r.Type, r.Value)python
req = models.DescribeRecordListRequest()
req.Domain = "example.com"
req.Limit = 3000
resp = client.DescribeRecordList(req)
matches = [r for r in resp.RecordList if "api" in r.Name or "api" in r.Value]
for r in matches:
print(r.RecordId, r.Name, r.Type, r.Value)Create records
创建记录
python
def create_record(domain, sub_domain, record_type, value, ttl=600, mx=None):
req = models.CreateRecordRequest()
req.Domain = domain
req.SubDomain = sub_domain # use "@" for the apex
req.RecordType = record_type
req.RecordLine = "默认" # "Default" line — works in all environments
req.Value = value
req.TTL = ttl
if mx is not None:
req.MX = mx
resp = client.CreateRecord(req)
return resp.RecordIdpython
def create_record(domain, sub_domain, record_type, value, ttl=600, mx=None):
req = models.CreateRecordRequest()
req.Domain = domain
req.SubDomain = sub_domain # 根域名使用"@"
req.RecordType = record_type
req.RecordLine = "默认" # "默认"线路——适用于所有环境
req.Value = value
req.TTL = ttl
if mx is not None:
req.MX = mx
resp = client.CreateRecord(req)
return resp.RecordIdA record
A记录
rid = create_record("example.com", "www", "A", "1.2.3.4")
rid = create_record("example.com", "www", "A", "1.2.3.4")
CNAME (note: Value MUST end with a dot for absolute target)
CNAME记录(注意:值必须以点结尾表示绝对域名)
rid = create_record("example.com", "api2", "CNAME", "api.example.com.")
rid = create_record("example.com", "api2", "CNAME", "api.example.com.")
MX (priority via mx=)
MX记录(通过mx参数设置优先级)
rid = create_record("example.com", "@", "MX", "mail.example.com.", mx=10)
rid = create_record("example.com", "@", "MX", "mail.example.com.", mx=10)
TXT (SPF)
TXT记录(SPF)
rid = create_record("example.com", "@", "TXT", '"v=spf1 include:_spf.google.com ~all"')
rid = create_record("example.com", "@", "TXT", '"v=spf1 include:_spf.google.com ~all"')
ACME challenge for cert issuance
证书签发的ACME挑战记录
rid = create_record("example.com", "_acme-challenge", "TXT", '"<validation-token>"')
undefinedrid = create_record("example.com", "_acme-challenge", "TXT", '"<validation-token>"')
undefinedUpdate an existing record
更新现有记录
python
req = models.ModifyRecordRequest()
req.Domain = "example.com"
req.RecordId = 123456789
req.SubDomain = "www"
req.RecordType = "A"
req.RecordLine = "默认"
req.Value = "5.6.7.8"
req.TTL = 600
client.ModifyRecord(req)python
req = models.ModifyRecordRequest()
req.Domain = "example.com"
req.RecordId = 123456789
req.SubDomain = "www"
req.RecordType = "A"
req.RecordLine = "默认"
req.Value = "5.6.7.8"
req.TTL = 600
client.ModifyRecord(req)Delete a record
删除记录
python
undefinedpython
undefinedConfirm with the user before running.
执行前请与用户确认。
req = models.DeleteRecordRequest()
req.Domain = "example.com"
req.RecordId = 123456789
client.DeleteRecord(req)
undefinedreq = models.DeleteRecordRequest()
req.Domain = "example.com"
req.RecordId = 123456789
client.DeleteRecord(req)
undefinedRecord types
记录类型说明
| Type | Use For | Example Value |
|---|---|---|
| IPv4 address | |
| IPv6 address | |
| Alias to another hostname | |
| Mail server | |
| SPF / DKIM / DMARC / domain verification / ACME | |
| Delegate subzone | |
| Service discovery | |
| Cert Authority Authorization | |
| 类型 | 用途 | 示例值 |
|---|---|---|
| IPv4地址 | |
| IPv6地址 | |
| 别名指向其他主机名 | |
| 邮件服务器 | |
| SPF/DKIM/DMARC/域名验证/ACME挑战 | |
| 子域名委托 | |
| 服务发现 | |
| 证书颁发机构授权 | |
CNAME apex restriction
CNAME根域名限制
DNSPod (like every other DNS service) does not support on the apex (the bare domain) when other record types exist. Use for the apex; for subdomains. If the upstream is itself a hostname (e.g. an EdgeOne / CDN endpoint), use the record type via the EdgeOne console — DNSPod itself doesn't have an type.
CNAME@ACNAMEAliasALIASDNSPod(与其他所有DNS服务一样)不支持在根域名(裸域名)上设置CNAME记录(当存在其他记录类型时)。根域名请使用记录;子域名可使用记录。如果上游目标是主机名(例如EdgeOne/CDN节点),请通过EdgeOne控制台设置记录类型——DNSPod本身没有类型。
@ACNAMEAliasALIASRecordLine ("线路")
线路(RecordLine)
DNSPod can serve different values to different ISPs / regions via . For 99% of cases pick (Default) — it serves to every resolver. Other common lines: , , , , . Use the console to set up split-horizon DNS; the API just lets you write the records.
RecordLine"默认""电信""联通""移动""境外""国内"DNSPod可通过为不同ISP/地区提供不同的记录值。99%的场景下选择即可——它会向所有解析器提供记录。其他常见线路包括:、、、、。可通过控制台配置智能DNS;API仅用于写入记录。
RecordLine"默认""电信""联通""移动""境外""国内"Verifying changes
验证修改结果
bash
dig @119.29.29.29 www.example.com +short # 119.29.29.29 = DNSPod's recursor
dig www.example.com +trace # follow the delegation chainDNSPod propagation is usually under a minute on its own resolver and bounded by the TTL elsewhere. Use while iterating; raise to once stable.
TTL=60600bash
dig @119.29.29.29 www.example.com +short # 119.29.29.29 = DNSPod的递归解析器
dig www.example.com +trace # 跟踪解析链DNSPod自身解析器的记录生效时间通常在1分钟内,其他解析器的生效时间则受TTL限制。迭代测试时可设置,稳定后再调整为。
TTL=60600Important reminders
重要提醒
- CNAME values need a trailing dot to be absolute (). Without it, DNSPod won't reject — but resolvers will hate you.
api.example.com. - Confirm deletes with the user — there's no undo. The is required, so search first to be sure.
RecordId - Don't rotate records lightly — losing nameserver delegation takes the entire domain offline until you fix it.
NS - TXT values for SPF/DMARC need to stay under 255 chars per chunk. For longer policies, split into multiple quoted strings within one TXT value.
- DNSPod has separate quota for free / paid plans on and
RecordCount. Check the console ifRecordsPerMinuteerrors appear.LimitExceeded
- CNAME值需要以点结尾以表示绝对域名(如)。如果不加,DNSPod不会拒绝请求,但解析器会出现异常。
api.example.com. - 删除操作请先确认——删除后无法恢复。操作需要,所以请先搜索确认正确的ID。
RecordId - 不要轻易修改NS记录——丢失域名服务器委托会导致整个域名无法访问,直到修复为止。
- SPF/DMARC的TXT值需控制在每段255字符以内。对于较长的策略,可拆分为多个带引号的字符串合并到一个TXT值中。
- DNSPod的免费版和付费版在(记录数量)和
RecordCount(每分钟记录操作数)上有不同配额。如果出现RecordsPerMinute错误,请查看控制台。LimitExceeded
Console links
控制台链接
- DNSPod console: https://console.cloud.tencent.com/cns
- API reference: https://www.tencentcloud.com/document/product/1097/40694