AVA Studio ID

lisensi

Iklan

AVA Studio
30 December 2022, 11:26 WITA (GMT+8)
Last Updated 2022-12-30T06:47:02Z

Script Mikrotik RouterOS || Allow Use Of ntp.org Pool Service For NTP

Advertisement
Mikrotik RouterOS Script || Allow Use Of ntp.org Pool Service For NTP


To allow the use of the NTP (Network Time Protocol) pool service provided by ntp.org, you will need to configure your device or system to use one or more of the NTP servers that are part of the ntp.org pool. This can typically be done by specifying the address of one or more of the NTP servers in the device or system's NTP configuration settings.

The NTP pool service provided by ntp.org is a collection of volunteer-run NTP servers that are available for use by anyone who needs to synchronize their device's clock with an accurate time source. The servers in the pool are distributed around the world and are intended to provide reliable and accurate time synchronization for devices and systems that are connected to the internet.

To use the NTP pool service provided by ntp.org, you will need to know the address of one or more of the NTP servers in the pool. You can find a list of the servers in the pool at the following URL:

https://www.ntppool.org/en/

Once you have identified one or more NTP servers that you would like to use, you can specify their addresses in your device or system's NTP configuration settings. This will allow your device or system to synchronize its clock with the time provided by the NTP servers, ensuring that it has an accurate and reliable time source.

This script checks the hostnames of the two NTP servers, compares the result to the current NTP settings, and changes the addresses if they differ. This script is necessary because RouterOS does not allow hostnames to be used in NTP configuration. Two scripts are used. The first one defines some system variables used by other scripts and the second one does the main thing.

Mikrotik RouterOS Script || Allow Use Of ntp.org Pool Service For NTP
# System configuration script - "GlobalVars"
:put "Setting system globals";

# System name
:global SYSname [/system identity get name];

# Email address to send notifications to
:global SYSsendemail "mail@my.address";

# Email address to send notifications from
:global SYSmyemail "routeros@my.address";

# Mail server to use
:global SYSemailserver "1.2.3.4";

# NTP pools to use (check to www.pool.ntp.org)
:global SYSntpa "0.uk.pool.ntp.org";
:global SYSntpb "1.uk.pool.ntp.org";
# Check & set NTP servers - "setntppool"

# We need to use the following globals which must be defined here even
# though they are also defined in the script we call to set them.
:global SYSname;
:global SYSsendemail;
:global SYSmyemail;
:global SYSmyname;
:global SYSemailserver;
:global SYSntpa;
:global SYSntpb;

# Load the global variables with the system defaults
/system script run GlobalVars

# Resolve the two ntp pool hostnames
:local ntpipa [:resolve $SYSntpa];
:local ntpipb [:resolve $SYSntpb];

# Get the current settings
:local ntpcura [/system ntp client get primary-ntp];
:local ntpcurb [/system ntp client get secondary-ntp];

# Define a variable so we know if anything's changed.
:local changea 0;
:local changeb 0;

# Debug output
:put ("Old: " . $ntpcura . " New: " . $ntpipa);
:put ("Old: " . $ntpcurb . " New: " . $ntpipb);

# Change_primary if required
:if ($ntpipa != $ntpcura) do={
:put "Changing primary NTP";
/system ntp client set primary-ntp="$ntpipa";
:set changea 1;
}

# Change secondary if required
:if ($ntpipb != $ntpcurb) do={
:put "Changing secondary NTP";
/system ntp client set secondary-ntp="$ntpipb";
:set changeb 1;
}

# If we've made a change, send an e-mail to say so.
:if (($changea = 1) || ($changeb = 1)) do={
:put "Sending e-mail.";
/tool e-mail send \
to=$SYSsendemail \
subject=($SYSname . " NTP change") \
from=$SYSmyemail \
server=$SYSemailserver \
body=("Your NTP servers have just been changed:Primary:Old: " . $ntpcura . "New: " \
. $ntpipa . "SecondaryOld: " . $ntpcurb . "New: " . $ntpipb);
}

to Scheduler entry:

/system scheduler add \
comment="Check and set NTP servers" \
disabled=no \
interval=12h \
name=CheckNTPServers \
on-event=setntppool \
policy=read,write,test \
start-date=jan/01/1970 \
start-time=16:00:00

No comments:

Post a Comment

Selamat Datang

X
X