Syed Jahanzaib Personal Blog to Share Knowledge !

November 14, 2012

Howto configure NTP client in Mikrotik / Ubuntu for Asia/Karachi


For Personnel Reference

Following Guide contains two section as following …

  1. Howto configure NTP client in Mikrotik
  2. 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
/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 5.x
/system ntp client
set enabled=yes mode=unicast primary-ntp=91.189.91.157 secondary-ntp=0.0.0.0

# For Mikrotik 6.x -------
/system ntp client
set enabled=yes primary-ntp=91.189.91.157 secondary-ntp=0.0.0.0

After few seconds you will get the correct date/time … [or reboot the RB]

NOTE: For other countries, change the timezone according to there local timings.


 * Howto configure NTP in Ubuntu

First install NTP service on Ubuntu sing below command,

apt-get install ntp

  • Issue following command to add NTP Server info in /etc/ntp.conf file
echo "server 91.189.91.157" > /etc/ntp.conf
  • Now copy PK Time zone to /etc

(You may copy time zone file according to your zone. Look in the folder to match)

cp /usr/share/zoneinfo/Asia/Karachi /etc/localtime

Use the below command to update the time.

ntpdate -u   91.189.91.157

Now type

date

to verify if time i snow updated correctly


Regard’s
Syed Jahanzaib

Advertisements

11 Comments »

  1. 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

    Like

    Comment by kevin — April 4, 2013 @ 3:25 AM

  2. thanks my teacher

    Like

    Comment by spidernet2013 — September 18, 2013 @ 3:20 PM

  3. we thank Allah for giving us YOU!

    Like

    Comment by Day-Day Ahmed — December 31, 2013 @ 12:46 AM

  4. after putting above settings still not working please solve the issue RB750GL

    Like

    Comment by Muhammad Nauman — May 13, 2014 @ 10:03 AM

  5. hi,
    i configured as explained above but time is not updating..please assist..i have an RB 1100 running ROS 6.14

    Like

    Comment by Michael — June 11, 2014 @ 6:19 AM

  6. 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”;

    Like

    Comment by dqbl — December 13, 2014 @ 4:53 AM

  7. 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,

    Like

    Comment by sam — June 8, 2017 @ 5:21 AM


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: