CentOS – Configuring As A Time Server

CentOS – Configuring As A Time Server

Introduction

This article explains how to configure a NTP (Network Time Protocol) Server on CentOS 5.5 which can then be used for synchronising other hosts in the network.

Pre-Requisites

  • A basic installation of CentOS 5.5

Installing NTP

Installing the NTP service is a simple task using yum which will also install any package dependencies which are required.  To install the NTP service using yum perform the following steps :-

  • In the command prompt execute the following command :-

yum install ntp

Configuring The NTP Service

The next step is to configure the NTP service on the server by editing the ntp.conf file. To configure NTP service on the server perform the following steps :-

  • Edit the file /etc/ntp.conf
  • In the default ntp.conf file for CentOS find the line # Hosts on local network are less restricted and add the line below :-

restrict {Your IP Subnet} mask {Your Subnet Mask} nomodify notrap

E.G. – restrict 10.20.30.0 mask 255.255.255.0 nomodify notrap

  • Save and Exit the file

This will configure the server to allow access from your own IP Subnet to the NTP service so that other hosts are able to synchronise their time with it.  It will also be configured to use the CentOS ntp pool servers to synchronise its time with so must have access to the internet.

If you are unable to connect to the internet with your server or already have a NTP server within your organisation then perform the following steps :-

  • Edit the file /etc/ntp.conf
  • In the default ntp.conf file for CentOS find the line # Use public servers from the pool.ntp.org project
  • Comment out the following three lines with a # (Hash) symbol as shown below :-

#server 0.centos.pool.ntp.org

#server 1.centos.pool.ntp.org

#server 2.centos.pool.ntp.org

  • Next add a line below the lines above as shown below :-

server {Your NTP Server IP Address}

E.G. – server 10.20.30.40

  • Save and Exit the file

Synchronising The Servers Time

The next step is to synchronise the servers time manually to ensure that it has the correct time.  To synchronise the servers time perform the following steps :-

  • In the command prompt execute the following command to synchronise to the CentOS NTP Pool servers :-

ntpdate 0.centos.pool.ntp.org

  • The command should reply back with a reply along the lines of whats shown below :-

adjust time server 91.121.138.209 offset -n.nnnnnn sec

  • If synchronising to your own NTP Server execute the following command :-

ntpdate {Your NTP Server IP Address}

E.G. – ntpdate 10.20.30.40

  • The command should reply back with a reply along the lines of whats shown below :-

adjust time server 91.121.138.209 offset -n.nnnnnn sec

Configuring The NTP Service To Start Automatically

The next step is to configure the NTP service to start automatically on boot.  To configure the NTP service to start automatically on boot perform the following steps :-

  • In the command prompt execute the following command :-

chkconfig ntpd on

Starting The NTP Service

The final step in the configuration is to start the NTP service on the server.  To start the NTP service on the server perform the following steps :-

  • In the command prompt execute the following command :-

service ntpd start

Confirming The NTP Service Is Running

To confirm that the NTP service is now running on the server perform the following steps :-

  • In the command prompt execute the following command :-

ps -ef | grep ntpd

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