Tag Archive : ntp

/ ntp

OpenWRT Time Synchronization

December 9, 2015 | Article | No Comments

OpenWRT router isn’t shipped with hardware clock like PC does. Therefore, the clock is reset each time the WRT is reboot to a hardcoded time setting.

Applying OpenWRT to some time-critical device would result in unexpected result. A valid clock system need to be implemented. As there are no local source could be used as reference, the only option is using external clock as resource. The cheapest afford will be connecting to a NTP (Network Time Protocol) Server and synchronizing the time with it. The synchronization is done automatically every reboot and the time will be periodically synchronized when OpenWRT is running.

To periodically synchronizing the device, make sure cron is running and able to create a scheduled task to perform the time synchronization.

In this article we will discuss about time synchronization between OpenWRT and NTP Server. Here, I assume we have build and NTP server or at least have a NTP to be used as reference.


Prior to performing time synchronization, make sure the time zone is set correctly on OpenWRT device. Check the value of /etc/TZ to know it.

Since I’m located in Indonesia (West Indonesia Time / WIT), my timezone would be GMT+7. Therefore I will set my Timezone by:

echo GMT-7 > /etc/TZ

Well, the offset in the TZ valu specifies the time value added to local time to get a UTC value. Therefore, if the local timezone is West of the Prime Meridian, the value is positive and it would be negative if it is East. As a result, TZ Must be set to GMT-7 for a timezone that is GMT+7.

Obtain Materials

To communicate with NTP Server, we need a capable client. The client in this scope is ntpclient which can be installed using opkg.

opkg install ntpclient


In addition, this package may also create an init script, /etc/init.d/S55ntpclient, with following content:

/usr/sbin/ntpclient -c 1 -S -h pool.ntp.org &

This will cause ntpclient to attempt a once-off time synchronization to pool.ntp.org at boot time. Additional parameters can also be passed to ntpclient to tell it to periodically perform a time synchronization with a specified host.

Here is the content of /etc/init.d/S55ntpclient I use.


# Kill any existing ntpclient process (they can get stuck if no route to target host)
/usb/bin/killall ntpclient

# do time synchronization
/usr/sbin/ntpclient -l -h -c 1 -s &

Here I have a local NTP Server so I use it. Replace the address to ntp address you want.

A fellow user said that when initial time synchronization fails (ie, no route to the specified time server or similar), ntpclient will hang and will never attempt another synchronization. This can typically occur if the time synchronization is being done over a wireless link or a VPN which may not yet be up then the init script is run.

For periodic time synchronization, we will utilize cron.

Create /etc/crontabs/root with the following content:

# timesync every 15 minutes
*/15 * * * * /etc/init.d/555ntpclient

Restart crond to make change take effect:

killall crond; /etc/init.d/S60cron

At this point, our device should be synchronized for every 15 minutes

Install and Configure a NTP Server on FreeBSD

December 9, 2015 | Article | No Comments

NTP (Network Time Protocol) is an Internet protocol used for synchronizing the clocks of networked computers. Computer clock accuracy is instrumental in providing a consistent reference for system log files, email timestamps, time-activated scripts, and so on. The NTP system is capable of keeping your computer’s clock accurate to within a few milliseconds of an accurate time server. Time servers are usually connected directly to a source of accurate time (e.g., atomic or GPS clocks).

In this article we will discuss about installing and configuring FreeBSD as NTP Server. For that purpose, I use:

  1. FreeBSD amd64 8.3

How it Works?

A server running the NTP daemon periodically synchronizes its clock to one or more established time servers. Over time, the NTP daemon calculates the system-specific clock error. If the system temporarily loses Internet connectivity, the NTP daemon will keep the system clock accurate using this error (or clock drift) data until it can re-synchronize with a time server.


Make sure we have became superuser before proceeding to next stage.


Installation of NTP is as easy as install other ports.

cd /usr/ports/net/ntp
make config
make install clean


At this point, we have successfully install NTP Server. Before using it, we should do a minimum configuration.

Create a drift file for storing clock correction data. In this article, we will store the drift file at /etc/ntp as drift. The drift file is used as

touch /etc/ntp/drift

Next, we will select appropriate time servers for synchronization. Choose the closest time server available to our network (geographically). The updated list of public time servers can be viewed here. This will make our server adjusting the time relative to our selected time server. Note this, and at least use three network servers.

Next, create and edit /etc/ntp.conf. This file will be our NTP’s configuration file. Later, write these into ntp.conf:

server time.example1.com iburst
server time.example2.com iburst
server time.example3.com iburst
driftfile /etc/ntp/drift
logfile /var/log/ntp.log

In above example, we use time.example1.com, time.example2.com, and time.example3.com as our network time server.

To make our NTP daemon automatically started at boot time, add following lines to /etc/rc.conf:


Social media & sharing icons powered by UltimatelySocial