Install and Configure NTP on CentOS 5.X

This is just a brief howto about installing and configuring NTPD (Network Time Protocol Daemon) on a Linux server which in this case is specifically NTPD. First we will install ntpd, then update the current time on the server, configure ntpd to restart on server boot, and then start ntpd.

  1. Install NTPD: Run the below command to install ntpd via yum.
  2. [root@server ~]# yum install ntp
    

  3. Update NTPD Configuration: Modify the ntpd.conf file located in the /etc/ directory.
  4. [root@server ~]# vi /etc/ntp.conf
    

    Add the below to the /etc/ntp.conf file. Please be aware that there are many configuration options that can be added to /etc/ntp.conf that make it more secure and the below is a very basic configuration file.

    # 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
    restrict default kod nopeer notrap nomodify
    restrict -6 default kod nopeer notrap nomodify
    
    # 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
    
    # Use public servers from the pool.ntp.org project.
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    server 0.rhel.pool.ntp.org
    server 1.rhel.pool.ntp.org
    server 2.rhel.pool.ntp.org
    
    # Undisciplined Local Clock. This is a fake driver intended for backup
    # and when no outside source of synchronized time is available.
    server 127.127.1.0 # local clock
    fudge 127.127.1.0 stratum 10
    
    # Drift file. Put this in a directory which the daemon can write to.
    # No symbolic links allowed, either, since the daemon updates the file
    # by creating a temporary in the same directory and then rename()'ing
    # it to the file.
    driftfile /var/lib/ntp/drift
    
  5. Set NTPD to Start: Update chkconfig to have ntpd start when the server restarts.
  6. [root@server ~]# chkconfig ntpd on
    [root@server ~]# chkconfig --list | grep ntp
    
  7. Update Server Time: Use rdate to set the server time. Install it if it is not already installed.
  8. [root@server ~]# yum install rdate
    [root@server ~]# rdate -s cuckoo.nevada.edu
    
  9. Start NTPD: Run the below command to start NTP (Network Time Protocol).
  10. [root@server ~]# /etc/init.d/ntpd start
    

    Use the below command to verify NTPD is now running. You should see output similar to what is below the ps command.

    [root@server ~]# ps -ef | grep ntp
    ntp 15120 1 0 21:50 ? 00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
    root 20420 19746 0 22:44 pts/3 00:00:00 grep ntp
    
Share