Setting static DNS record for each DHCP lease

From MikroTik Wiki
Revision as of 15:59, 20 September 2006 by Pedja (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

Code:

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
        }  \

};