Community discussions

MikroTik App
 
jkarras
Member Candidate
Member Candidate
Topic Author
Posts: 226
Joined: Fri Sep 06, 2013 3:07 am
Location: Utah, USA

Script for setting DNS entries for DHCP clients

Sun Jul 20, 2014 12:59 am

All, I noticed while looking for scripts that would set DNS entries for DHCP leases that all of them were old and used the scheduler. I have created a new script using the new on-lease script functionality in ROS 6.2+. My code is on Github at the link below. Would love feedback.

https://github.com/karrots/ROS-DDNS
 
User avatar
Etz
Member Candidate
Member Candidate
Posts: 178
Joined: Thu Mar 27, 2014 10:09 am
Location: Estonia

Re: Script for setting DNS entries for DHCP clients

Sun Jul 20, 2014 9:48 am

You could use this, instead of "static topdomain" name in script.
:set topdomain [/ip dhcp-server network get number=0 domain];
And every time you add an DHCP-server, increment it by 1 ;)

Then if you change domain under dhcp server settings, it always changes in script accordingly.

And you can tie your TTL to lease time aswell:
:set ttl [/ip dhcp-server get number=0 lease-time];
Did those modifications to that script and its working just great for me, thank you :)
 
jkarras
Member Candidate
Member Candidate
Topic Author
Posts: 226
Joined: Fri Sep 06, 2013 3:07 am
Location: Utah, USA

Re: Script for setting DNS entries for DHCP clients

Sun Jul 20, 2014 4:24 pm

Good idea on using the DHCP network for the domain name. The trouble is that there isn't always a one to one mapping between the network and the DHCP server. I could do a comparison between the IP the client received and the list of networks to find the value. I'll have to look into the IP comparison operators offered by ROS scripting.

I thought about tying the TTL to the lease time but there are many reasons you may want the TTL lower. If a computer properly leaves the network and releases its DHCP address then the name will be freed up early for example. Also DNS clients are not going to be requesting the record at the start of the lease. So a 30min lease with a client requesting a DNS lookup at 25min into that lease means a 30min cache store. In addition the resolver built into windows caches for 24 hrs regardless of TTL.

In the DNS/DHCP setup at my place of employment the software has a static DDNS ttl which by default is 1 minute. I was mainly emulating that behavior.
 
User avatar
Etz
Member Candidate
Member Candidate
Posts: 178
Joined: Thu Mar 27, 2014 10:09 am
Location: Estonia

Re: Script for setting DNS entries for DHCP clients

Mon Jul 21, 2014 8:17 am

Good idea on using the DHCP network for the domain name. The trouble is that there isn't always a one to one mapping between the network and the DHCP server. I could do a comparison between the IP the client received and the list of networks to find the value. I'll have to look into the IP comparison operators offered by ROS scripting.
This would be actually awesome, mine is just "quick and dirty" solution... :)

And actually you are quite right about TTL.
 
DaveN
newbie
Posts: 25
Joined: Sun Jan 15, 2017 10:29 pm

Re: Script for setting DNS entries for DHCP clients

Wed Jan 18, 2017 8:40 am

Thanks jkarras for the script - it work very well.
I've created a mod as a proposed method to dynamically determine the domain:
https://github.com/daven-que/ROS-DDNS
 
rftnon
newbie
Posts: 29
Joined: Fri Feb 28, 2014 6:34 pm

Re: Script for setting DNS entries for DHCP clients

Sun Feb 12, 2017 8:52 pm

Thanks ...
This is useful and good ...

Who is online

Users browsing this forum: f1lat0v and 83 guests