Hi,
using your script for a while now, runs quite well.
But my log is flooded with entrys like
"static dns entry changed by xxx"
any way to run the script without entrys to the log?
Hi,
using your script for a while now, runs quite well.
But my log is flooded with entrys like
"static dns entry changed by xxx"
any way to run the script without entrys to the log?
Those are system-generated log messages. RouterOS doesn’t provide any flags to quiet them or any options to silence one script. You’ve got four options: 1) Disable logging system-wide, 2) Disable logging at the beginning and re-enable it at the end of the script (you might lose other messages), 3) Stop using the script, or 4) Ignore the log messages.
Love the script but wondering if there is a way to make it not write to flash for every update if changes are not detected? I lowered the run time down to every hour for now but it would be amazing if there was an easy way to have it check for duplicates/same data before pushing the writes(or maybe it does this and there are still a lot?). Thank you!
Xecuter2, sure. You’d need a second conditional before line 22. Something like this:
> ([:len [/ip dns static find where name=$regdomain address!=$hostaddr comment=$magiccomment]] = 0)
It could be done more efficiently by storing a reference to the first lookup and then checking its address. I might update the script to do this in the future.
This worked a charm, thank you again. I set to 1 minute and writes do not increase at all now unless something changes. I know it probably doesn't matter much with how many writes the flash can take but less seems better. I noticed that the DHCP lease store to disk also must check for past entries as it does not write unless something changes.
There are lots of scripts out there; this one is simple, easy to read, and does the job. Thanks :)
Good post. You are right about renewals. However I want to suggest you try using both the lease script trigger AND a scheduled trigger. You can have it scheduled less frequently if you want since the trigger based one will cover most of the cases (without latency).
Love this script, thank you!
Instead of:
> :local hostaddr [/ip dhcp-server lease get value-name=address $lease]
.. I use:
> :local hostaddr [/ip dhcp-server lease get value-name=active-address $lease]
This way static leases in a waiting/not-active state don't get added to DNS.
I found this slight difference useful for hosts which can connect via two (or more) interfaces each of which has its own IP address, e.g. a notebook computer that is sometimes on the network wired and other times on the network wireless, but only one at a time, and for which only one hostname is desired in DNS (so that, whichever interface happens to be the one that is connected from time to time, just one hostname will always be the right name to use to find the host).
With the original code, which reads the address parameter, static waiting addresses do get added to DNS (and might get added before the other, actually active address, resulting in only the non-active address being put into DNS, I guess because it's found after the actually-active DHCP lease, and it overwrites the DNS entry that the actually active DHCP lease had just been read by the script and written into static DNS).
And here are the lines of my updated script, which checks to see if there already exists a static DNS entry with the correct IP address for each active DHCP lease. This avoids the log filling up (and the static RAM being unnecessarily re-written) with static DNS entries being set for DHCP leases which this script had already added on previous runs.
Thank you for the hint in an earlier comment about how to do this.
> # For DHCP leases with something/anything in the hostname, and an active IP address ...
> :if (([:len $hostname] > 0) and ([:len $hostaddr] > 0)) do={
> :foreach domain in $domains do={
> :local regdomain "$hostname.$domain"
> :set activehosts ($activehosts, $regdomain)
>
> # Only if a DNS entry does not already exist
> :if ([:len [/ip dns static find where name=$regdomain]] = 0) do={
> /ip dns static add name=$regdomain address=$hostaddr comment=$magiccomment ttl=$dnsttl
> } else={
> # But if a DNS entry did already exist, check if its IP address needs to change
> :local statichostnumber [/ip dns static find where name=$regdomain]
> :local hostoldaddr [/ip dns static get $statichostnumber address]
> :if ($hostaddr != $hostoldaddr) do={
> /ip dns static set address=$hostaddr [/ip dns static find name=$regdomain comment=$magiccomment]
> }
> }
> }
> }
>}
Jan