Dynamic DNS (DDNS) API Tutorial
13 viewsThis tutorial explains how to use the Dynamic DNS (DDNS) update API to automatically update DNS records with IPv4/IPv6 auto-detection. The API uses a simple HTTP GET request structure and supports intelligent IP recognition for seamless updates.
API Endpoint
https://store.9v4.com/update_dns.php
Parameters
| Parameter | Required | Description | Example |
|---|---|---|---|
key |
Yes | API authentication key | key=xxx |
order_id |
Yes | Service subscription ID | order_id=12 |
record_name |
Yes | DNS record name (use @ for root domain) |
record_name=@ or record_name=www |
record_value |
Optional | IP address to update (omit for auto-detect) | record_value=192.168.1.1 |
record_type |
Optional | Record type (A, AAAA, or CNAME); auto-detected if omitted |
record_type=A (auto-detected if omitted) |
record_ttl |
Optional | TTL value (default: 600) |
record_ttl=300 |
record_priority |
Optional | MX priority (required only for MX records) | record_priority=10 |
Note
The domain_name parameter has been removed. Record management is handled via record_name and your account configuration.
IPv4/IPv6 Auto-Detection
When both record_value and record_type parameters are omitted, the system performs automatic IP detection:
https://store.9v4.com/update_dns.php?key=xxx&order_id=xxx&record_name=@
Auto-Detection Logic:
- Detects visitor's real IP (IPv4 or IPv6)
- Sets
record_typetoAfor IPv4 - Sets
record_typetoAAAAfor IPv6 - Supports manual override of all parameters
Integration Examples
1. Linux/macOS Cron Job
#!/bin/bash API_KEY="your_api_key_here" ORDER_ID="XXX" RECORD="@"
Auto-detect implementation
curl -s "https://store.9v4.com/update_dns.php?key=$API_KEY&order_id=$ORDER_ID&record_name=$RECORD" >> /var/log/ddns.log
Crontab Setup:
*/5 * * * * /usr/local/bin/ddns_update.sh # Update every 5 minutes
2. Python Script
import requests import os
def update_ddns():
params = {
'key': os.getenv('DDNS_API_KEY'),
'order_id': os.getenv('DDNS_ORDER_ID'),
'record_name': os.getenv('DDNS_RECORD')
}
response = requests.get('https://store.9v4.com/update_dns.php', params=params)
return response.text
if name == "main":
print(update_ddns())
3. Windows PowerShell
$apiKey = "your_api_key_here" $orderId = "12" $record = "server"
Auto-detect using visitor's IP
Invoke-RestMethod -Uri "https://store.9v4.com/update_dns.php?key=$apiKey&order_id=$orderId&record_name=$record"
4. Embedded Device (Arduino/ESP8266)
#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h>
const char* ssid = "YourWiFi";
const char* password = "YourWiFiPass";
const char* apiKey = "your_api_key_here";
const char* record = "esp8266";
``
void setup() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
}
``
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = "https://store.9v4.com/update_dns.php?key=";
url += apiKey;
url += "&order_id=12&record_name=";
url += record;
http.begin(url); int httpCode = http.GET(); http.end(); delay(300000); // 5 minutes
}
}
5. Manual IPv4 Update
https://store.9v4.com/update_dns.php?key=xxx&order_id=xxx&record_name=@&record_value=1.2.3.4&record_type=A
6. Manual IPv6 Update
https://store.9v4.com/update_dns.php?key=xxx&order_id=xxx&record_name=@&record_value=2607:fb90::1&record_type=AAAA
Best Practices
1. Security
- Always use HTTPS
- Store API keys in environment variables
- Restrict API key usage to trusted IPs
2. Rate Limiting
- Minimum 5 minutes between updates
- Avoid excessive requests during debugging
3. Error Handling
- Check API response text for success messages
- Implement retry logic for network failures
- Log all update attempts
4. Multi-IP Support
Use separate records for IPv4/IPv6 when:
- Behind dual-stack networks
- Testing IPv6-only setups
- Different subdomain requirements
Troubleshooting
| Error Code | Description | Solution |
|---|---|---|
| 401 | Authentication failed | Verify API key and order_id |
| 400 | Invalid parameters | Check required parameters |
| 200 | Request succeeded | Check DNS propagation (may take 60 min) |
| -1 | Network error | Check internet connectivity |
Response Format
- Success:
DNS record updated successfully - Error:
Error: [Error message details]
Support
For technical assistance:
- Include your
order_idin all support requests - Provide sanitized API request URLs
- Share platform and environment details
- Include error logs and response messages
Note: DNS changes may take 0–60 minutes to propagate globally. Use tools like dig example.com to verify updates.