How to Install and Configure NTP Server On CentOS 6.2

In this post, i will show you on how to configure NTP server for time adjustment. NTP, Network Time Protocol, it is an Internet protocol used to synchronize the clocks of computers or servers to some NTP server on internet or intranet.

Install the following package using yum :

    [root@centos62 ~]# yum install ntp -y
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base:
     * extras:
     * updates:
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package ntp.i686 0:4.2.4p8-2.el6.centos will be installed
    --> Finished Dependency Resolution
    Dependencies Resolved
     Package       Arch           Version                          Repository                      Size
     ntp           i686           4.2.4p8-2.el6.centos             CentOS6.2-Repository           436 k
    Transaction Summary
    Install       1 Package(s)
    Total download size: 436 k
    Installed size: 1.1 M
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : ntp-4.2.4p8-2.el6.centos.i686                                                    1/1
      ntp.i686 0:4.2.4p8-2.el6.centos

Once NTP is installed you need to update the configuration file, ntp.conf located in the /etc directory :

    [root@centos62 ~]# 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 -6 ::1
    # Hosts on local network are less restricted.
    restrict mask nomodify notrap
    # Use public servers from the project.
    # Please consider joining the pool (
    #broadcast autokey        # broadcast server
    #broadcastclient                        # broadcast client
    #broadcast autokey            # multicast server
    #multicastclient              # multicast client
    #manycastserver         # manycast server
    #manycastclient autokey # manycast client
    # Undisciplined Local Clock. This is a fake driver intended for backup
    # and when no outside source of synchronized time is available.
    #server     # local clock
    #fudge stratum 10
    # Enable public key cryptography.
    includefile /etc/ntp/crypto/pw
    # Key file containing the keys and key identifiers used when operating
    # with symmetric key cryptography.
    keys /etc/ntp/keys
    # Specify the key identifiers which are trusted.
    #trustedkey 4 8 42
    # Specify the key identifier to use with the ntpdc utility.
    #requestkey 8
    # Specify the key identifier to use with the ntpq utility.
    #controlkey 8
    # Enable writing of statistics records.
    #statistics clockstats cryptostats loopstats peerstats

Start the NTP service :

    [root@centos62 ~]# /etc/rc.d/init.d/ntpd start
    Starting ntpd:                                             [  OK  ]

Set NTP service start at boot :

    [root@centos62 ~]# chkconfig ntpd on
    [root@centos62 ~]# ntpq -p
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================    5 u   33   64    1   55.809  35573.8   0.001
     enterprise.wyne    3 u   32   64    1   55.888  35592.2   0.001     4 u   31   64    1   54.479  35584.8   0.001

To verify the NTP service is now running on the server using the following command :

    [root@centos62 ~]# ps -ef | grep ntpd
    ntp      22682     1  0 22:38 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ -g
    root     22696  2377  0 22:40 pts/0    00:00:00 grep ntpd

The command should return two lines showing that the ntpd process is running and the ntpd grep process you executed

    [root@centos62 ~]# service ntpd status
    ntpd (pid  22682) is running...
    [root@centos62 ~]# watch ntpq -c lpee
    Every 2.0s: ntpq -c lpee                                                    Tue Feb  7 23:00:24 2012
         remote           refid      st t when poll reach   delay   offset  jitter
    ============================================================================== .RMOT.          16 u    -   64    0    0.000    0.000   0.000 .INIT.          16 u    -   64    0    0.000    0.000   0.000

Leave a Reply

Your email address will not be published. Required fields are marked *