Setting static DNS record for each DHCP lease

From MikroTik Wiki
Revision as of 10:47, 29 October 2007 by Normis (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Run this in scheduler and it will add static dns entry for each DHCP lease.

:set topdomain "yourdomain.com" ;
/ip dhcp-server lease ;
:foreach i in=[find] \
do={  \
    /ip dhcp-server lease ;
        :if ([:len [get $i host-name]] > 0) do={ \
           :set hostname ([get $i host-name] . "." . $topdomain); \
           :set hostip [get $i address]; \
           :put ( $hostname . " : " . $hostip ) ; \
           /ip dns static ;
           :foreach di in [find] do = { :if ([get $di name] = $hostname) do {/ip dns static remove $di }}
           /ip dns static add name=$hostname address=$hostip
         }  \
};