Skip to content

Synchronize CentOS System Clock with Network Time Protocol (NTP)

Synchronize System Clock with Network Time Protocol (NTP) in CentOS

Computers, like any digital device, have clocks in them. Aside from telling users the time, they also provide a sequencing mechanism for internal core functions and digital circuitry. However, sometimes these clocks malfunction. It might be because of a bad CMOS battery or a timezone mix-up. Fortunately, CentOS, or any Linux box for that matter, have a tool that synchronizes its clocks with central servers.

The Network Time Protocol (NTP) is such a tool. It functions as an initial configuration setter and auto updater for Linux or CentOS boxes.

Install NTPD

If  ntp is not installed in your CentOS box, here’s how to do it with yum:

#yum install ntp

Configuration NTPD

As opposed to Windows boxes that require special applications to configure, Linux daemons and services can be modified with a basic text editor. Stored in the /etc/ directory, these configuration files can be easily changed to suite your needs. The Network Time Protocol daemon is no different. Here’s how to configure it:

#vi /etc/ntp.conf

 For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
ph.pool.ntp.org
server pool.ntp.org
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

#broadcast 192.168.1.255 autokey                 # broadcast server
#broadcastclient                                                # broadcast client
#broadcast 224.0.1.1 autokey                         # multicast server
#multicastclient 224.0.1.1                               # multicast client
#manycastserver 239.255.254.254                # manycast server
#manycastclient 239.255.254.254 autokey  # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

Once the configuration file is open, add “ph.pool.ntp.org” as indicated above. It must be noted that there are a lot of available Network Time Protocol servers on the internet. Save the file.

For a complete list, check this link: http://www.pool.ntp.org/zone/asia.

Restart NTPD

To apply the changes the NTP daemon must be restarted. On the terminal, type this:

#service ntpd restart

Synchronize the System Clock with the NTP Servers

#ntpdate ph.pool.ntp.org

 

Comments are closed.