How To Configure NTP Server On Ubuntu 14.04

Having your servers synchronize it’s time to a time server will surely ease administrator task to maintain the servers and do troubleshooting if requires. Especially when they need to find related errors in the logs and when the actual issue happened. By default, all OS will synchronize to their default time server and timezone. However, we can overwrite it and force the servers to synchronize to our own time server if we had one.

To setup a time server is so easy. In this tutorial we use our Ubuntu 14.04 as our own time server. To setup, you just need to run below command in your terminal.

apt-get update && apt-get install ntp -y

your os will automatically update your repository and proceed to install ntp server to your operating system. Now you need to edit /etc/ntp.conf using your preferred editor. as for us, we use nano.

nano /etc/ntp.conf

now you will need to add additional lines to the config file. Below are some of the samples.

server <your server ip address> iburst
restrict -4 default kod notrap nomodify
restrict -6 default kod notrap nomodify

to allow your server to serve time service to specific network you may specify below line

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

Once done, save it and restart your ntp service.

service ntp restart

Test Other server to Synchronize to your newly prepared time server.

assuming that you have an existing ubuntu server. You may proceed to install service below:

apt-get update && apt-get install ntp -y

Once it has been installed, you may open /etc/ntp.conf using your preferred editor and hash all configuration start with server and a new server statement to your newly install ntp server ip.

#server time.ubuntu.com
server 192.168.1.1 iburst

save the changes that you had made and restart the ntp service once again.

service ntp restart

now you can check your ntp synchronization status  using below command.

ntpq -c peer
ntpq -c assoc

if you find status reject inside the output of ntpq -c assoc, you may need to run below  command to force it to synchronize.

hwclock -w

The reason being we face this issue is probably because of the time drift between the hardware clock is to big causing the system will not make any changes to it and will not synchronize.