Page 1 of 1

NTP client using FQDN?

Posted: Sun Feb 23, 2014 10:33 pm
by alexburke
Hello!

My RB450G (RouterOS v6.10) is configured as an NTP client. I would like to use an FQDN (pool.ntp.org, europe.pool.ntp.org, etc) to respect load-balancing. How can I do this?

Thanks in advance!

Re: NTP client using FQDN?

Posted: Mon Feb 24, 2014 2:59 pm
by nerdtron
Just input the FQDN in the /system ntp
The FQDN will be converted to IP addresses once the router does nslookup.

Re: NTP client using FQDN?

Posted: Mon Feb 24, 2014 4:27 pm
by alexburke
Just input the FQDN in the /system ntp
The FQDN will be converted to IP addresses once the router does nslookup.
It performs the DNS resolution precisely once: the moment you configure it, and then never again. Load balancing (the whole point of pool.ntp.org) is lost. This is not a solution, unfortunately. :(

Re: NTP client using FQDN?

Posted: Mon Feb 24, 2014 4:32 pm
by lunchboxrts
I wish ros would save the fqdn instead of the ip. I use a script set to run every 30 min to update the settings with the new addresses to respect the load balancing.
#get ntp ip's
:local ntpipa [:resolve 0.us.pool.ntp.org];
:local ntpipb [:resolve 1.us.pool.ntp.org];
:local cn;

#get current ip's
:local ntpcura [/system ntp client get primary-ntp];
:local ntpcurb [/system ntp client get secondary-ntp];

#change primary if needed
:if  ($ntpipa != $ntpcura) do={
#:log info "Changing primary NTP ($ntpcura --> $ntpipa)";
/system ntp client set primary-ntp="$ntpipa";
:set cn "1";
}

#change secondary if needed
:if  ($ntpipb != $ntpcurb) do={
#:log info "Changing secondary NTP ($ntpcurb --> $ntpipb)";
/system ntp client set secondary-ntp="$ntpipb";
:set cn "1";
}

:if ($cn != "1") do={
#:log info "No NTP updates required";
}

#:log info "Finished updating NTP IP's";

Re: NTP client using FQDN?

Posted: Mon Feb 24, 2014 7:10 pm
by alexburke
I use a script set to run every 30 min to update the settings with the new addresses to respect the load balancing.
What a hack, but if need be, I'll do it. Please excuse the ignorance; how exactly is this added and scheduled?

Re: NTP client using FQDN?

Posted: Tue Feb 25, 2014 4:27 am
by nerdtron
You can include 2 ntp pools for time sync. Isn't that enough?

In creating scripts and schedules, go to System>Scripts. Click the plus sign to add an entry. Give it a name (ex: check-time) and then paste your whole script in the Sorce box.Click OK to save.
Then go to System>Scheduler. Click the plus sign to add an entry. Give it a name (ex:check-time). Set Start Time to “startup”, set Interval to “00:30:00” to run it every 30 minutes. Put the following in the On Event box:
/system script run check-time
Click OK to save it.

Re: NTP client using FQDN?

Posted: Fri Feb 28, 2014 12:37 am
by alexburke
Brilliant. Thanks so much!

Re: NTP client using FQDN?

Posted: Mon Mar 17, 2014 5:47 pm
by alexburke
I wish ros would save the fqdn instead of the ip. I use a script set to run every 30 min to update the settings with the new addresses to respect the load balancing.
This doesn't seem to work; here's the script:
:log info "NTP IP update script triggered.";
       
       #Get NTP IPs
       :local ntpipa [:resolve 0.europe.pool.ntp.org];
       :local ntpipb [:resolve 1.europe.pool.ntp.org];
       :local cn;
       
       #Get Current IPs
       :local ntpcura [/system ntp client get primary-ntp];
       :local ntpcurb [/system ntp client get secondary-ntp];
       
       #change primary if needed
       :if  ($ntpipa != $ntpcura) do={
       :log info "Changing primary NTP IP ($ntpcura --> $ntpipa)";
       /system ntp client set primary-ntp="$ntpipa";
       :set cn "1";
       }
       
       #change secondary if needed
       :if  ($ntpipb != $ntpcurb) do={
       :log info "Changing secondary NTP IP ($ntpcurb --> $ntpipb)";
       /system ntp client set secondary-ntp="$ntpipb";
       :set cn "1";
       }
       
       :if ($cn != "1") do={
       :log info "No NTP updates required";
       }
       
       :log info "Finished updating NTP IP addresses";
The only output I get is
echo: script,info NTP IP update script triggered.

Re: NTP client using FQDN?

Posted: Mon Mar 17, 2014 5:57 pm
by rextended
Why complicate all????

You just need this:
/system scheduler
add interval=30m name=check_time_servers on-event="/system ntp client set enabled=yes mode=unicast primary-ntp=[:resolve 0.europe.pool.ntp.org] secondary-ntp=[:resolve 1.europe.pool.ntp.org];" policy=read,write start-date=jan/02/1970 start-time=00:02:00
this update ntp servers each 30 min [and start to do it after 2 min from RB is powered].

Re: NTP client using FQDN?

Posted: Mon Mar 17, 2014 7:06 pm
by alexburke
Why complicate all????

You just need this:
/system scheduler
add interval=30m name=check_time_servers on-event="/system ntp client set enabled=yes mode=unicast primary-ntp=[:resolve 0.europe.pool.ntp.org] secondary-ntp=[:resolve 1.europe.pool.ntp.org];" policy=read,write start-date=jan/02/1970 start-time=00:02:00
this update ntp servers each 30 min [and start to do it after 2 min from RB is powered].
A nice clean solution. Thank you!

Re: NTP client using FQDN?

Posted: Mon Mar 17, 2014 7:43 pm
by rextended
If you have liked the solution, please add Karma