From 488439a306520c1462c2902bfe0c816a9cd1fcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=91=D0=B0=D1=80=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 8 Aug 2024 13:21:29 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20DHCP2DNS=5FFULLUPDATE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DHCP2DNS_FULLUPDATE | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 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