Step-by-Step Config Guide of NTP server and client on Centos7/RHEL7/Fedora22

NTP (Network Time Protocol) server

NTP stands for Network Time Protocol(NTP). It is an Internet protocol used to synchronize computer clock times in a network of computers.

ntp_server_ittroubleshooter-in_new

I this article we will see how you can install and configure NTP server on CentOS7/RHEL7/Fedora22 and sync the time with the window as well as Linux client machine.

Outline of NTP server:

Package                    : ntp
Configuration File   : /etc/ntp.conf
Usage                        :  On the network, NTP server can be synchronized with an external timing source(Public NTP pool time service) to keep all the servers in your network in-sync with an accurate time.
Daemon                    : ntpd
Port number            : 123

My setup:

We use 3 systems,one as the NTP Linux server other as NTP client Linux as well as window server. Let look at below details for more understanding.

NTP  server ip add. and hostname: 192.168.1.10 (server1).
NTP client ip add. and hostname(Linux): 192.168.1.11 (Client1).
NTP client ip add. and hostname(Window): 192.168.1.12(client3).

To configure the NTP server the steps are:

1.) Install the package.

Install the Package using yum command. If you are not configured the YUM server, refer the link(PART2: YUM (Yellowdog Updater Modified))

#yum install -y ntp

[root@server1 yum.repos.d]# yum install ntp 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-22.el7.centos will be installed
. . . .

Transaction Summary
=======================================
Install  1 Package (+2 Dependent packages)

Total download size: 693 k
Installed size: 1.6 M
Is this ok [y/d/N]: y

2) Edit the ntp (/etc/ntp.conf) config file.

Before that, First Go to the Public NTP pool time service, refer the link (http://www.pool.ntp.org/en/). Click on the active servers from the Continent area on  right side of this page(In our case we are using Asia continent).

ntp_active_server
Then search your country location from the zones and click on that(We are using Singapore time zone).

ntp_server_ittroubleshooter-in_cont

As below screen shot, Copy all pool.ntp.org lines.

ntp_server_ittroubleshooter-in_cont_conf

Then, Open the /etc/ntp.conf file and add the comments of Public Servers from pool.ntp.org (Defaults list) and replace it with the list provided for your country like in the screen shot above.

#vim /etc/ntp.conf

ntp_conf

Note: Before that take the backup of ntp configuration(/etc/ntp.conf) file.
You need to add the network range you allow to receive requests from your network to synchronize time with this server.(In our case we are using 192.168.1.0/24 network)

#restrict 192.168.1.0 netmask 255.255.255.0 nomodify notrap

ntp_network

There are some access control entries that are;

  • The nomodify options prevents any changes to the configuration.
  • The notrap option prevents ntpdc control message protocol traps.
  • The noquery option prevents ntpq and ntpdc queries, but not time queries, from being answered.
  • The nopeer option prevents a peer association being formed.
  •  The Prefer option is specified that server is preferred over other servers.

3) Allow ntp service on firewall of the server.

The Port of ntp service is 123/UDP. It is work on the transport layer. To allow the port on Centos7/RHEL7/Fedora22, following command used.

[root@server1 ~]# firewall-cmd --add-service=ntp --permanent
success
[root@server1 ~]# firewall-cmd --reload
success 
[root@server1 ~]#

4) Start the service and make the service enable even after reboot of the server.

#systemctl start <service name> This command used for start the service of ntpd and # systemctl enable <service name> This command used for enable the service after reboot of the server.

[root@server1 ~]# systemctl start ntpd
[root@server1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@server1 ~]#

5) Check Server Time Sync.

After start the service of ntp service. We need to execute the “ntpq -p” command to verify NTP peers synchronization status.

[root@server1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-188.166.215.214 14.61.98.51      4 u 4971   64    3  189.346    3.851   5.604
+ntpmon.dcs1.biz .PPS.            1 u 4971   64    1  392.630  -33.878   8.423
*210.23.25.77    .GPS.            1 u 4971   64    1  382.748  -31.973   8.430
+dyn107-b57-acce 192.36.143.150   2 u 4971   64    3  175.410   53.911   6.343
[root@server1 ~]#

Then, Check the your system time.

In case there are problem with the NTP service, To find out the error you can use dedicated log file.
Go to bottom of “ntp.conf” file and add the one configuration line, refer below screen shot.

#logfile /var/log/ntp.log

ntp_log_entry

 

Configure NTP Client on Centos7 Client

1) Install the ntp package on client system.

#yum install -y ntp

2) Edit the ntp configuration file.

Open the /etc/ntp.conf file with your editor and add the comments of Public Servers from pool.ntp.org (Defaults list) and replace it with the ntp server entry, refer the screen shot.

#vim /etc/ntp.conf

ntp_client

3) Start and enable the ntp service.

[root@client1 ~]# systemctl start ntpd
[root@client1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@client1 ~]#

4) Verify Client Time Sync with ntp server.

As shows below, Time synchronisation status of Client system with ntp server(Wait a few minutes for the server to synchronize time).

[root@client1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
=================================================
*192.168.1.10    58.146.176.233   2 u   46   64    3    0.386   -4.483   2.107
[root@client1 ~]# ntpstat
synchronised to NTP server (192.168.1.10) at stratum 3 
   time correct to within 8102 ms
   polling server every 64 s
[root@client1 ~]#

Note: Using “ntpstat” command will show network time synchronisation status

Configure NTP Client on Window Client

In our case we are using window 7 machine. To synchronize time with your NTP server first go to Start –> Control Panel. Select the Date and Time option, refer below screenshot.

window_cp

After that below window will open, then move to “Internet Time” tab and click “Change settings” button.

window_it

NTP server’s hostname (if your system is on DNS or hosts file contains entries)or IP address and click “Update now” button.

window_con

Hope this post will help Linux/Unix beginners. Please share you feedback and Comments. Till then connected with us at ittroubleshooter.in .!!!