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 6.x -------
/system ntp client
set enabled=yes primary-ntp=211.19.59.28 secondary-ntp=103.47.76.177

# 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 timezone according to there local timings.


 * 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

%d bloggers like this: