For Personnel Reference
Following Guide contains two section as following …
- Howto configure NTP client in Mikrotik
- Howto configure NTP client in Ubuntu
Recently I received email from a friend who was annoyed by the Mikrotik Router board date/time resetting upon every reboot. He was using USERMAN with above 500 users, so it was a big problem for him for the accounting perspective. He thought RB also have the battery to save the time/data 😀 , He asked me how he can replace the battery :p
Routerboards do not have an internal clock to keep time upon reboot. You have to configure NTP client to obtain ip from Time Server. Following are the scripts to update your NTP client and set time zone to +5 (for Karachi/Pakistan). Make sure you have enabled internet access on the router before configuring NTP. After configuring NTP, you dont have to manually configure the time CLOCK. This is very crucial for mikrotik to obtain correct time specially for LOG purposes and if you are doing user accounting by using Radius Server like USERMAN on it. For example if the RB reboots and the date/time resets to previous dates, then it can create lot of problems for user accounting. That’s why NTP client ensures that you always get the proper date/time upon every reboot or in routine. Use the following script to setup NTP client.
Note: I used ntp.ubuntu.com in this example. you can use other ntp servers available near you.
* Howto configure NTP in Mikrotik
/system clock set time-zone-name=manual # I set Timezone for KARACHI which is +5, you may change the time-zone according to your region /system clock manual set dst-delta=+00:00 dst-end="jan/01/1970 00:00:00" dst-start="jan/01/1970 00:00:00" time-zone=+05:00 # For Mikrotik 6.x ------- (make sure DNS resolving/Internet is working in MT) /system ntp client set enabled=yes primary-ntp=0.asia.pool.ntp.org secondary-ntp=1.asia.pool.ntp.org # For Mikrotik 5.x /system ntp client set enabled=yes mode=unicast primary-ntp=211.19.59.28 secondary-ntp=103.47.76.177
After few seconds you will get the correct date/time … [or reboot the RB]
NOTE: For other countries, change the time zone according to there local region.
* Howto configure NTP in Ubuntu
First install NTP service on Ubuntu sing below command,
apt-get -y install ntp ntpdate
Now copy PK Time zone to /etc [u may change it according to your timezone]
(You may copy time zone file according to your zone. Look in the folder to match)
cp /usr/share/zoneinfo/Asia/Karachi /etc/localtime
Restart the NTP service
sudo /etc/init.d/ntp restart
After few seconds , system time will auto sync with the NTP servers.
Now type
date
to verify if time i now updated correctly
Additional TIP:
ntp.conf for local time server, un tested
root@ubuntu:~# #cat /etc/ntp.conf driftfile /var/lib/ntp/ntp.drift statistics loopstats peerstats clockstats filegen loopstats file loopstats type day enable filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable server 127.127.1.0 fudge 127.127.1.0 startum 8 server 192.168.100.1 server 82.165.36.179 server 0.ubuntu.pool.ntp.org server 1.ubuntu.pool.ntp.org server 2.ubuntu.pool.ntp.org server 3.ubuntu.pool.ntp.org server ntp.ubuntu.com restrict -4 default kod notrap nomodify nopeer noquery restrict -6 default kod notrap nomodify nopeer noquery restrict 127.0.0.1 restrict ::1
Regard’s
Syed Jahanzaib
i’m kevin Please i need help i use rb450g(mipsbe) i delete all file and now when i open userman is open but not with all option.
iwan to know how to restore with initial file.
please
LikeLike
Comment by kevin — April 4, 2013 @ 3:25 AM
thanks my teacher
LikeLike
Comment by spidernet2013 — September 18, 2013 @ 3:20 PM
Welcome !
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — September 18, 2013 @ 3:56 PM
we thank Allah for giving us YOU!
LikeLike
Comment by Day-Day Ahmed — December 31, 2013 @ 12:46 AM
after putting above settings still not working please solve the issue RB750GL
LikeLike
Comment by Muhammad Nauman — May 13, 2014 @ 10:03 AM
hat issue you are having?
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — May 13, 2014 @ 10:08 AM
hi,
i configured as explained above but time is not updating..please assist..i have an RB 1100 running ROS 6.14
LikeLike
Comment by Michael — June 11, 2014 @ 6:19 AM
Hi, for people who have trouble with ntp / sntp mikrotik not working, try this script. I have been searching, trying, upgrading all day, but did not get the mikrotik client to work properly, so I have made this simple script, which does the job, without using ntp or sntp. greetings, Richard.
# This script copyright by Richard Kloostra
# You can use, modify, delete free of any charge
# Please submit modifications back to me. richard@riklsat.com
# last modified, Dec 12 2014 , v1.0
# Applies to ROS 6.23 / RB1100
# CREDITS
# Credit to http://www.timeapi.org
############
# Variables
############
:local newgmtmonstring (“newgmtmonstring”.”txt”)
:local gmtmonurl “http://www.timeapi.org/gmt/now?format=\\b”
:local mon
:local newgmtdaystring (“newgmtdaystring”.”txt”)
:local gmtdayurl “http://www.timeapi.org/gmt/now?format=\\d”
:local day
:local newgmtyearstring (“newgmtyearstring”.”txt”)
:local gmtyearurl “http://www.timeapi.org/gmt/now?format=\\Y”
:local year
:local newgmttimestring (“newgmttimestring”.”txt”)
:local gmttimeurl “http://www.timeapi.org/gmt/two+hours+ago?\\H:\\M:\\S”
:local gmttime
:local newgmtoffset (“newgmtoffset”.”txt”)
############
# Script
############
/tool fetch mode=http url=$gmtmonurl dst-path=$newgmtmonstring
:set mon [/file get ($newgmtmonstring) contents]
:log info ($mon)
/tool fetch mode=http url=$gmtdayurl dst-path=$newgmtdaystring
:set day [/file get ($newgmtdaystring) contents]
:log info ($day)
/tool fetch mode=http url=$gmtyearurl dst-path=$newgmtyearstring
:set year [/file get ($newgmtyearstring) contents]
:log info ($year)
/tool fetch mode=http url=$gmttimeurl dst-path=$newgmttimestring
:set gmttime [/file get ($newgmttimestring) contents]
:log info ($gmttime)
/system clock set date=”$mon/$day/$year” time=”$gmttime”;
LikeLike
Comment by dqbl — December 13, 2014 @ 4:53 AM
thanks for the contribution.
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — December 29, 2014 @ 9:20 AM
1-do we have to change time zone in usermanager too?
2- and can we use
0.pool.ntp.org
1.pool.ntp.org
to set ntp client ?
regards,
LikeLike
Comment by sam — June 8, 2017 @ 5:21 AM
userman will use mikrotik default time.
and yes you can any ntp of your choice.
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — June 9, 2017 @ 9:21 AM