Automatically Update Dynamic IP to Cloudflare DNS Using a MikroTik Router
Most home internet connections use dynamic IP — meaning your public IP changes from time to time. This is a problem if you host services at home such as:
- Home server / NAS
- CCTV / Camera system
- Remote SSH / RDP access
- VPN for remote connection
- Docker self-hosted applications
When the IP changes, your domain stops pointing to the correct server, and all remote access fails. The best way to solve this is to automatically update your domain’s DNS record every time your router’s IP changes.
In this guide, we will use:
- MikroTik Router
- Cloudflare DNS
- A simple script + scheduler
Once configured, the router will auto-update your DNS every time your IP changes — fully hands-off.
✅ Prepare Cloudflare Credentials
-
Log in to Cloudflare
-
Go to My Profile → API Tokens
-
Create a token with permission:
Zone → DNS → Edit
-
Copy this token (will be used in the script)
Next, gather the following:
| Required | Where to get |
|---|---|
| Bearer Token | Cloudflare API token |
| Zone ID | Cloudflare → Website → Overview |
| DNS Record ID | Can be queried via API or Cloudflare UI |
If you need DNS Record ID, you can get it with a simple curl command:
curl --request GET \
--url https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $bearer_token' | jq
✅ Add Script to MikroTik
Go to System → Scripts → Add New Script

Create a script to update the IP in MikroTik
Example script for updating IPv4:
Replace:
| Field | Your Value |
|---|---|
wanif |
Your WAN interface name (ex: pppoe-out1, ether1, vlan10) |
Bearer Token |
Your Cloudflare API token |
zoneId |
Your Cloudflare Zone ID |
hostId |
Your DNS record ID |
hostName |
Your domain/subdomain |
✅ Schedule Automatic Updates
Go to System → Scheduler → Add New
- Interval: 1 minute (or 5 minutes)
- On Event: run the script you just created
This ensures Cloudflare DNS always matches your latest public IP.

Chạy script mỗi 1 phút
✅ (Optional) IPv6 Support
If your ISP provides IPv6, you can also auto-update AAAA records. A full version with IPv4 + IPv6 is available on GitHub:
https://github.com/skywirex/mikrotik-cloudflare-ddns-scripts