English version: README.md | Русская версия: README_ru.md
Automatically update Cloudflare DNS records when your MikroTik router's public IP address changes. Supports both IPv4 and IPv6.
- MikroTik Cloudflare DDNS Script
- ✅ IPv4 and IPv6 support
- ✅ Multiple domains/subdomains
- ✅ Cloudflare proxy toggle (orange/gray cloud)
- ✅ Efficient IP change detection
- ✅ Automatic API updates
- ✅ Compatible with RouterOS 7.20+
- MikroTik Router running RouterOS 7.20 or later
- Cloudflare Account with:
- Domain(s) added to Cloudflare
- API Token with DNS edit permissions
- IP Cloud Service enabled on MikroTik
/ip cloud set ddns-enabled=yes- Log in to Cloudflare Dashboard
- Go to My Profile → API Tokens
- Click Create Token
- Use the Edit zone DNS template or create custom token with:
- Permissions:
Zone → DNS → Edit - Zone Resources:
Include → Specific zone → [Your Domain]
- Permissions:
- Copy the generated token
- Go to your domain in Cloudflare Dashboard
- Scroll down on the Overview page
- Find Zone ID in the right sidebar
Use Cloudflare API or this curl command:
curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Find your domain's record in the response and copy its id.
- Open the script file
- Replace
CF_AUTH_TOKENwith your actual Cloudflare API token - Configure your domains in the array:
:local domains {
"example.com,zone_id,record_id,true,v4";
"ipv6.example.com,zone_id,record_id,false,v6";
"subdomain.example.com,zone_id,record_id,true,v4"
}
Array format: "domain,zone_id,record_id,proxied,ip_version"
domain: Your domain/subdomainzone_id: Cloudflare Zone IDrecord_id: DNS Record IDproxied:true(orange cloud) orfalse(gray cloud)ip_version:v4for IPv4 orv6for IPv6
- Copy the entire script
- In MikroTik terminal or WebFig/WinBox:
- Go to System → Scripts
- Click Add New
- Name:
cloudflare-ddns - Paste the script
- Click OK
/system scheduler add \
name=cloudflare-ddns-update \
on-event=cloudflare-ddns \
interval=5m \
start-time=startupThis runs the script every 5 minutes and on router startup.
:local domains {
"home.example.com,abc123zone,xyz789record,true,v4"
}
:local domains {
"ipv6.example.com,abc123zone,xyz789record,false,v6"
}
:local domains {
"example.com,abc123zone,rec1id,true,v4";
"www.example.com,abc123zone,rec2id,true,v4";
"ipv6.example.com,abc123zone,rec3id,false,v6";
"*.example.com,abc123zone,rec4id,true,v4"
}
:local domains {
"example.com,abc123zone,ipv4_record_id,true,v4";
"example.com,abc123zone,ipv6_record_id,true,v6"
}
/log print where topics~"script"You should see messages like:
✅ Updated example.com (A) → 203.0.113.45
✅ Updated ipv6.example.com (AAAA) → 2001:db8::1
/system script run cloudflare-ddns/system script environment printLook for lastCloudflareIPv4 and lastCloudflareIPv6.
- Verify scheduler is enabled:
/system scheduler print - Check if IP Cloud is working:
/ip cloud print
- Verify API token has correct permissions
- Check Zone ID and Record ID are correct
- Ensure token hasn't expired
- Verify IPv6 is configured on your router
- Check IP Cloud has IPv6 address:
/ip cloud print - Ensure your ISP provides public IPv6
- IP might not have changed
- Check logs:
/log print where topics~"script" - Verify domains array format is correct
- Don't share your script with the token included
- Use environment variables or separate config if sharing
- Regularly rotate API tokens
- Use minimal permissions (only DNS edit for specific zones)
Modify the scheduler interval:
/system scheduler set cloudflare-ddns-update interval=10mEdit the ttl value in the script (default is 300 seconds):
:local json ("{\"type\":\"" . $recordType . "\",\"name\":\"" . $domain . \
"\",\"content\":\"" . $currentIP . \
"\",\"ttl\":120,\"proxied\":" . $proxied . "}")
Remove or adjust the delay between updates:
:delay 1s
/system scheduler remove cloudflare-ddns-update
/system script remove cloudflare-ddns
/system script environment remove lastCloudflareIPv4
/system script environment remove lastCloudflareIPv6MIT License - Feel free to modify and distribute
Issues and pull requests are welcome!
Created for MikroTik RouterOS 7.20+ with Cloudflare DNS integration