mirror of
https://github.com/pothi/mikrotik-scripts.git
synced 2025-06-25 15:38:35 +02:00
Add a script to configure NTP client
This commit is contained in:
parent
732a3adc66
commit
c875527384
1 changed files with 66 additions and 0 deletions
66
scripts/ntp-client.rsc
Normal file
66
scripts/ntp-client.rsc
Normal file
|
@ -0,0 +1,66 @@
|
|||
# List of public servers... https://gist.github.com/mutin-sa/eea1c396b1e610a2da1e5550d94b0453
|
||||
|
||||
# variables
|
||||
# timezone
|
||||
:local tz
|
||||
:set tz "+05:30"
|
||||
|
||||
# To be used as the primary NTP server
|
||||
:local ipNTP
|
||||
:local ipNTPcomment
|
||||
# IP based NTP server - when DNS is unavailable.
|
||||
:set ipNTP "128.138.140.44"
|
||||
:set ipNTPcomment "From https://tf.nist.gov/tf-cgi/servers.cgi"
|
||||
|
||||
# To be used as the secondary NTP server
|
||||
:local poolNTPorg
|
||||
:set poolNTPorg [:resolve pool.ntp.org]
|
||||
|
||||
# To be used for DNS based NTP servers
|
||||
:local ntp1
|
||||
:local ntp2
|
||||
:set ntp1 "time.cloudflare.com"
|
||||
:set ntp2 "time.google.com"
|
||||
|
||||
:put "Primary NTP: $ipNTP ($ipNTPcomment)"
|
||||
:put "Secondary NTP: $poolNTPorg (pool.ntp.org)"
|
||||
:put "DNS NTP 1: $ntp1"
|
||||
:put "DNS NTP 2: $ntp2"
|
||||
|
||||
# configure timezone
|
||||
# /system clock manual set time-zone=$tz
|
||||
:put "Timezone: $tz\n"
|
||||
:put "Clock info..."
|
||||
|
||||
/system clock print
|
||||
|
||||
# Find Router OS version
|
||||
|
||||
:local rosVersion
|
||||
:set rosVersion [:tonum [:pick [/system resource get version] 0 1]]
|
||||
# following works as well.
|
||||
# :set rosVersion [:pick [/system/routerboard/get current-firmware] 0 1]
|
||||
|
||||
:put "\nRouter OS Version: $rosVersion\n"
|
||||
|
||||
|
||||
if ( $rosVersion = 7 ) do={
|
||||
:put "Code for ROSv7 executed."
|
||||
/system ntp client servers
|
||||
add address=128.138.140.44 comment="NIST.gov"
|
||||
add address=[ :resolve pool.ntp.org ] comment="pool.ntp.org"
|
||||
add address=time.google.com
|
||||
add address=time.cloudflare.com
|
||||
} else={
|
||||
:put "Code for ROSv6 executed."
|
||||
/system ntp client
|
||||
set primary-ntp=128.138.140.44
|
||||
set secondary-ntp=[ :resolve pool.ntp.org ]
|
||||
set server-dns-names=time.cloudflare.com,time.google.com
|
||||
}
|
||||
|
||||
/system ntp client set enabled=yes
|
||||
|
||||
|
||||
:put "NTP client info..."
|
||||
/system ntp client print
|
Loading…
Add table
Add a link
Reference in a new issue