Hetzner’s DNS Public API allows you to programmatically manage your domains, including creating subdomains. A subdomain is simply a DNS record under your main zone.
1. Get Your Zone ID
Each domain in Hetzner DNS has a unique zone_id. To find it:
curl -X GET "https://dns.hetzner.com/api/v1/zones" \
-H "Auth-API-Token: $API_TOKEN"
Look for your domain in the response and note its id. For example:
{
"id": "ABC...",
"name": "domain.com"
}
2. Add the Subdomain Record
Once you have the zone_id, you can create a subdomain by adding a DNS record. For example, to create xxx.domain.com pointing to 1.2.3.4:
curl -X POST "https://dns.hetzner.com/api/v1/records" \
-H "Auth-API-Token: $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"zone_id": "ABC...",
"type": "A",
"name": "xxx",
"value": "1.2.3.4",
"ttl": 300
}'
Parameters:
-
zone_id→ The zone where the subdomain will be added. -
type→ DNS record type (A,CNAME,MX, etc.). -
name→ Subdomain prefix (xxx). -
value→ IP address or target domain (1.2.3.4here). -
ttl→ Time-to-live in seconds (optional, default 300).
3. Verify the Subdomain
To confirm the subdomain was created:
curl -X GET "https://dns.hetzner.com/api/v1/records?zone_id=ABC..." \
-H "Auth-API-Token: $API_TOKEN"
Check for your new record in the response.
✅ Summary
- Subdomains are just DNS records in Hetzner.
- Use
GET /zonesto find yourzone_id. - Use
POST /recordsto add subdomains. - Use
GET /recordsto list or verify existing subdomains.
This approach lets you automate DNS management for your domains using Hetzner’s DNS API.
Top comments (0)