Script dhcp2dns
Posted: Sat Oct 25, 2014 6:26 pm
[/code2]Recently I had to configure dns entries for all hostnames in dhcp leases however scripts that I found usually recycle all static dns entries in a period of time, they need to manually set some parameters and dont take the advantage of the dhcp-server lease script feature.
I wrote this script and it seems to work well for multiple networks each with it's own domain setting set on a single router.
Can any of you guys take a look at it and check for any stability issues, or think of any scenarios in which it would not function properly?
Any ideas on how to optimise it are also welcome.
/ip dhcp-server lease-script
I wrote this script and it seems to work well for multiple networks each with it's own domain setting set on a single router.
Can any of you guys take a look at it and check for any stability issues, or think of any scenarios in which it would not function properly?
Any ideas on how to optimise it are also welcome.
/ip dhcp-server lease-script
ros code
:if ($leaseBound=1) do={ :foreach network in=[/ip dhcp-server network find] do={ :local netmask [/ip dhcp-server network get value-name=netmask $network]; :local leaseNetwork [:tostr ($leaseActIP & (~((0.0.0.1 << (32-$netmask))-1)))]; :if ([/ip dhcp-server network find address ~ [:tostr $leaseNetwork]] = $network) do={ :local leaseDomain [/ip dhcp-server network get value-name=domain $network]; :local leaseHostname ([/ip dhcp-server lease get [/ip dhcp-server lease find where active-mac-address=$leaseActMAC]]->"host-name"); :if ([:len $leaseHostname]!=0) do={ /ip dns static add address=$leaseActIP name=($leaseHostname.".".$leaseDomain) ttl=5m; } } } } else={ /ip dns static remove [/ip dns static find where address ~ "$leaseActIP"]; }