How to Setup NTP (Network Time Protocol) Server in CentOS/RHEL 7

0
184

Network Time Protocol: NTP- is a protocol which runs over port 123 UDP at Transport Layer and allows computers to synchronize time over networks for an accurate time. While time is passing by, computers internal clocks tend to drift which can lead to inconsistent time issues, especially on servers and clients logs files or if you want to replicate servers resources or databases.

Prerequisites:
*************************************************
To get the current configuration:
# timedatectl
# timedatectl  status
In the scrrentcast above, RTC time: is the hardware clock time.

To get the list of all the available time zones:
# timedatectl  list-timezones

To set your local timezone in Linux, we will use set-timezone switch as shown below

To set a specific time zone:
# timedatectl  set-timezone  “Asia/Dhaka”

It is always recommended to use and set the coordinated universal time, UTC
# timedatectl  set-timezone  UTC

You need to type the correct name timezone other wise you may get errors when changing the timezone, in the following example, the timezone “Asia/Kalkata” is not correct therefore causing the error.

Step 1: Install and configure NTP daemon
To install NTP Service:
# yum  install  ntp  -y

Enable and start NTP Servce:
# systemctl enable ntpd
# systemctl start ntpd

NTP Offical Public Pool Time Server address:
https://www.pool.ntp.org/zone/bd

NTP configuration is in the /etc/ntp.conf file.

Backup original file before edit.
# cp /etc/ntp.conf /etc/ntp.conf.ori

To edit Configuration file and add the country pools here:
# vim /etc/ntp.conf

# Allow clients from your networks to synchronize time with this server add:
restrict 192.168.20.0 netmask 255.255.255.0 nomodify notrap

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
:wq! (save and quit)

Step 2: Add Firewall Rules and Start NTP Daemon. NTP uses 123/UDP.
# firewall-cmd  –permanent  –add-service=ntp
# firewall-cmd  –reload

Step 3: Verify Server Time Sync Works
# ntpq -p
# date -R

Alternatively, to get a basic report:
# ntpstat

Step 4: Setup Windows NTP Client
**********************************************
Taskbar -> Change Date and Time Settings
-> Internet Time tab -> Change Settings
-> Check Synchronize with an Internet time server
-> put your server’s IP or FQDN on Server filed
-> Update now
-> OK.

To quickly synchronize a server:
# systemctl stop ntpd
# ntpdate pool.ntp.org
# systemctl start ntpd

logfile: /var/log/ntp.log

LEAVE A REPLY

Please enter your comment!
Please enter your name here