Community discussions

User avatar
Member Candidate
Member Candidate
Topic Author
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah

DHCP to DNS in 16-line script  [SOLVED]

Thu Aug 30, 2018 2:44 pm

This is simple and efficient script for registering FQDN=(host-name.domain) with TTL=10m
working 100% RouterOS 6.40.9 bugfix
:do {
:if ($leaseBound=1) do={
 :local HostName [/ip dhcp-server lease get number=[find where mac-address=$leaseActMAC] host-name];
  if ([:len $HostName]=0) do={:log error message="host-name Not Available";:error};
 :local Domain   [/ip dhcp-server network get number=[find where $leaseActIP in address] domain];
  if ([:len $Domain]=0) do={:log error message="domain Not Available";:error};
 :do {/ip dns static
  remove numbers=[find where name=($HostName . "." . $Domain)];
  add name=($HostName . "." . $Domain) address=$leaseActIP ttl=600s;
 } on-error={:log error message="Adding FQDN Failed"}
:if ($leaseBound=0) do={
 :do {/ip dns static
  remove numbers=[find where address=$leaseActIP];
 } on-error={:log error message="Removing FQDN Failed"}
} } on-error={:log error message="lease-script failed..."}

Who is online

Users browsing this forum: Majestic-12 [Bot] and 12 guests