commit 488439a306520c1462c2902bfe0c816a9cd1fcc2 Author: Игорь Барков Date: Thu Aug 8 13:21:29 2024 +0000 Добавить DHCP2DNS_FULLUPDATE diff --git a/DHCP2DNS_FULLUPDATE b/DHCP2DNS_FULLUPDATE new file mode 100644 index 0000000..aea426d --- /dev/null +++ b/DHCP2DNS_FULLUPDATE @@ -0,0 +1,29 @@ +:foreach lease in=[/ip dhcp-server lease find] do={ + :local hostName [/ip dhcp-server lease get $lease host-name] + + # Skip if hostName is empty + :if ( [ :len $hostName ] > 0 ) do={ + + :local ipAddress [/ip dhcp-server lease get $lease address] + :local ttl [/ip dhcp-server lease get $lease expires-after] + + # Find the corresponding network for the lease's IP address + :local networkId [/ip dhcp-server network find where $ipAddress in address] + :local domainName [/ip dhcp-server network get $networkId domain] + + :local fqdn "$hostName.$domainName" + :log info "Processing $fqdn with IP $ipAddress and TTL $ttl" + + # Remove any existing static DNS entries with the same IP address + :foreach oldRecord in=[/ip dns static find where address=$ipAddress and comment~"#DHCP"] do={ + :log info "Removing old DNS entry with IP $ipAddress" + /ip dns static remove $oldRecord + } + + # Add or update the static DNS entry + /ip dns static add address=$ipAddress name=$fqdn ttl=$ttl comment="#DHCP" disabled=no + } +} + +/system script run DHCP2DNS_CLEANUP +/system script run NATUPDATE \ No newline at end of file