This blog shows how to install and configure NTP (Network Time Protocol) Server and NTP Client on CentOS 8 / RHEL 8 or higher Linux system.
Configure NTP Server
- Install Chrony to Configure NTP Server for Time Synchronization:
[root@sujit ~]# dnf -y install chrony
- Edit Chrony configuration:
[root@sujit ~]# vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project to change to your own NTP server or others in your timezone.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.centos.pool.ntp.org iburst
server 0.np.pool.ntp.org iburst
server 0.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst
pool ntp.nict.jp iburst
# Allow NTP client access from local network.
allow 192.168.0.0/16
- Enable Chrony service:
[root@sujit ~]# systemctl enable --now chronyd
- Make exception in firewall services and reload firewall:
If Firewalld is running, allow NTP service. NTP uses [123/UDP].
[root@sujit ~]# firewall-cmd --add-service=ntp --permanent
success
[root@sujit ~]# firewall-cmd --reload
success
Now use the server’s IP address in client’s time zone configuration.
- Verify it works normally:
Command to check the NTP servers
[root@sujit ~]# chronyc sources
Command to check the NTP clients
[root@sujit ~]# chronyc clients
- To display time synchronization status, install NTPSTAT:
[root@client ~]# dnf -y install ntpstat
- Verify:
[root@client ~]# ntpstat
synchronised to NTP server (162.159.200.123) at stratum 4
time correct to within 79 ms
polling server every 512 s
Configure NTP Client
In linux, NTP Clients does not need to receive time synchronization requests from other hosts.
The configurations is mostly the same with server’s one.
- Install Chrony to Configure NTP Server for Time Synchronization:
[root@client ~]# dnf -y install chrony
- Edit Chrony configuration:
[root@client ~]# vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project to change to your own NTP server or others in your timezone.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.centos.pool.ntp.org iburst
server 0.np.pool.ntp.org iburst
server 0.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst
pool ntp.nict.jp iburst
- Enable Chrony service:
[root@client ~]# systemctl enable --now chronyd
- Verify it works normally:
[root@client ~]# chronyc sources
- To display time synchronization status, install NTPSTAT:
[root@client ~]# dnf -y install ntpstat
- Verify:
[root@client ~]# ntpstat
synchronised to NTP server (162.159.200.123) at stratum 4
time correct to within 79 ms
polling server every 512 s