Ben's notes

Linux, Unix, network, radio...

User Tools

Site Tools


CentOS 7 - install NTPd 4.2.8p10

This page describe the installation of NTPd as a server for other clients.


  • Download the latest NTPd source and md5 file from:
  • Verify md5 sum:
    # md5sum -c ntp-4.2.8p10.tar.gz.md5 
    ntp-4.2.8p10.tar.gz: OK
  • Install development tools, libraries and utilities:
    # yum groupinstall "Development Tools"
    # yum install libcap-devel libevent-devel openssl-devel perl-File-Fetch.noarch

Uninstall CentOS 7 NTPd package

  • Stop running the distribution default NTPd:
    # systemctl stop ntpd
  • Uninstall NTPd:
    # yum remove ntp
  • Exclude ntp packages in yum config:
    # echo "exclude=ntp*" >> /etc/yum.conf
  • Remove ntp user:
    # userdel ntp

Configure and compile NTPd

  • Extract NTPd sources:
    # tar zxf ntp-4.2.8p10.tar.gz
  • Configure:
    # cd ntp-4.2.8p10
    # ./configure --enable-linuxcaps --docdir=/usr/share/doc/ntp-4.2.8p10
  • Compile:
    # make

Create NTPd configuration

  • Create configuration file /etc/ntp.conf:
    driftfile /var/lib/ntp/drift
    restrict default kod nomodify notrap nopeer noquery
    restrict -6 default kod nomodify notrap nopeer noquery
    restrict ::1
    # pick servers near to you!
    server iburst
    server iburst
    server iburst
    server iburst
    # Enable writing of statistics records.
    statistics clockstats cryptostats loopstats peerstats
    leapfile /var/lib/ntp/leap-seconds.list

Configure OS

  • Create group:
    # groupadd ntp
  • Create user:
    # useradd -d /var/lib/ntp -g ntp -s /bin/false ntp
  • Add /usr/local/bin to path:
    # printf 'PATH=${PATH}:/usr/local/bin\n' > /etc/profile.d/
  • Create directory:
    # install -v -o ntp -g ntp -d /var/lib/ntp

Install NTPd

  • Install NTPd:
    # cd ntp-4.2.8p10
    # make install

Start NTPd

  • Start NTPd:
    # /usr/local/bin/ntpd -g -u ntp:ntp
  • Show version:
    # ntpd --version
    ntpd 4.2.8p10@1.3728-o Thu Jun  1 12:37:34 UTC 2017 (1)


Make sure your server can reach over FTP.

use Digest::SHA qw(sha1_hex); use File::Copy qw(move); use File::Fetch; use Getopt::Long qw(:config auto_help no_ignore_case bundling); use Sys::Syslog;

  • Schedule retrieval of leapfile using the update-leap script. For example put the script below in /etc/cron.weekly/
    # update leap file if necessary
    /usr/local/bin/update-leap -4 -s
    # stop ntpd
    /bin/pkill ntpd
    # start ntpd
    if /bin/pgrep ntpd >/dev/null; then
      echo "NTP daemon did not stop! Not trying to start another one."
      systemctl start ntpd

SystemD service

  • Create the file: /etc/systemd/system/ntpd.service
    Description=Network Time Service ntpdate.service sntp.service
    ExecStart=/usr/local/bin/ntpd -g -u ntp:ntp
  • Enable the service at boot:
    systemctl enable ntpd.service
  • Start the service:
    systemctl start ntpd.service
compile_ntp_on_centos7.txt · Last modified: 2021/10/09 15:14 by