Whenever you search for DHCP dynamic DNS scripts you find extremely complex examples like this:
https://wiki.mikrotik.com/wiki/Setting_static_DNS_record_for_each_DHCP_lease
However, before finding that, I wrote my own that seems to be working fine:
:local domain;
:local hostname;
:local recordExists;
:set domain "lan.leadtree-engineering.io";
:set hostname "$"lease-hostname".$domain";
:set recordExists [:len [/ip dns static find name=$hostname]];
:log info "fqdn: $hostname";
:log info "ip: $leaseActIP";
:log info "registering: $leaseBound";
:log info "matching records: $recordExists";
:if (1 = $leaseBound && 0 = $recordExists) do={
:log info "host doesn't exist and is registering, adding";
/ip dns static add name=$hostname address=$leaseActIP;
}
:if (1 = $leaseBound && 0 < $recordExists) do={
:log info "host already exists and is registering, updating";
/ip dns static set [find name=$hostname] address=$leaseActIP;
}
:if (0 = $leaseBound && 0 < $recordExists) do={
:log info "host already exists and is deregistering, removing";
/ip dns static remove [find name=$hostname];
}
:if (0 = $leaseBound && 0 = $recordExists) do={
:log info "hostname doesn't exist and is deregistering, there's nothing to do";
}
So, am I missing something? Is there a reason this isn’t the “right way”?
Thanks!