Created
June 8, 2024 23:08
-
-
Save aka13-404/7905fcf7a6642d7f21bbab789ad473b4 to your computer and use it in GitHub Desktop.
MIkrotik Cloudflare DDNS setup for DHCP-Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#zone id (domain) for which the records will be updated | |
:local cfZoneId "" | |
#api token with zone.dns permissions for the cfzoneid | |
:local cfApiToken "" | |
#record id which to update | |
#could be made into an array and iterator, but for me with one * and one @entry its not worth it | |
:local cfRecordId1 "" | |
:local cfRecordId2 "" | |
:local cfUrl "https://api.cloudflare.com/client/v4/zones/$cfZoneId/dns_records/" | |
:local cfAuthHeader "Authorization: Bearer $cfApiToken,Content-Type:application/json" | |
:if ($bound=1) do={ | |
:log info "IP lease received, updating DDNS" | |
:local cfBody "{\"content\": \"$"lease-address"\"}" | |
#This has cost me about 2 hours of my life. For whatever reason, if fetch executes immediately after receiving the lease-address, it will fail with "Download from api.cloudflare.com FAILED: Address not available" | |
:delay 1 | |
/tool fetch url="$cfUrl$cfRecordId1" http-header-field=$cfAuthHeader http-data=$cfBody mode=https keep-result=no http-method=patch | |
/tool fetch url="$cfUrl$cfRecordId2" http-header-field=$cfAuthHeader http-data=$cfBody mode=https keep-result=no http-method=patch | |
} else={ | |
:log info "No IP lease, nothing to be done with DDNS" | |
} | |
:log info "DHCP Client script ran successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment