Community discussions

MikroTik App
 
alexburke
just joined
Topic Author
Posts: 13
Joined: Sun Feb 23, 2014 10:29 pm

NTP client using FQDN?

Sun Feb 23, 2014 10:33 pm

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!
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: NTP client using FQDN?

Mon Feb 24, 2014 2:59 pm

Just input the FQDN in the /system ntp
The FQDN will be converted to IP addresses once the router does nslookup.
 
alexburke
just joined
Topic Author
Posts: 13
Joined: Sun Feb 23, 2014 10:29 pm

Re: NTP client using FQDN?

Mon Feb 24, 2014 4:27 pm

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. :(
Last edited by alexburke on Mon Feb 24, 2014 4:42 pm, edited 1 time in total.
 
lunchboxrts
Member Candidate
Member Candidate
Posts: 144
Joined: Sat Aug 19, 2006 6:40 am
Location: United States

Re: NTP client using FQDN?

Mon Feb 24, 2014 4:32 pm

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";
 
alexburke
just joined
Topic Author
Posts: 13
Joined: Sun Feb 23, 2014 10:29 pm

Re: NTP client using FQDN?

Mon Feb 24, 2014 7:10 pm

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?
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: NTP client using FQDN?

Tue Feb 25, 2014 4:27 am

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.
 
alexburke
just joined
Topic Author
Posts: 13
Joined: Sun Feb 23, 2014 10:29 pm

Re: NTP client using FQDN?

Fri Feb 28, 2014 12:37 am

Brilliant. Thanks so much!
 
alexburke
just joined
Topic Author
Posts: 13
Joined: Sun Feb 23, 2014 10:29 pm

Re: NTP client using FQDN?

Mon Mar 17, 2014 5:47 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: NTP client using FQDN?

Mon Mar 17, 2014 5:57 pm

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].
I'm Italian, not English. Sorry for my imperfect grammar.
 
alexburke
just joined
Topic Author
Posts: 13
Joined: Sun Feb 23, 2014 10:29 pm

Re: NTP client using FQDN?

Mon Mar 17, 2014 7:06 pm

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!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: NTP client using FQDN?

Mon Mar 17, 2014 7:43 pm

If you have liked the solution, please add Karma
I'm Italian, not English. Sorry for my imperfect grammar.

Who is online

Users browsing this forum: danmiles86 and 120 guests