NTP Server Setup in CentOS

Last modified: July 30, 2020
You are here:
Estimated reading time: 1 min

NTP – is a protocol used in Transport Layer which runs over port 123 UDP. NTP allows you automatically sync your system time with a remote server. Keeping your system’s date and time accurate with the use of NTP.  Your machine’s time will sync with the servers that are known to have accurate time. While time is passing by, the internal clock of computer slowly drifts away from a perfectly accurate setting. The accurate time in machine will helps when you need to check the logs from a particular time of day.

 

Install and Configure NTP

Installation of NTP

Debian/Ubuntu

# sudo aptitude update

# sudo aptitude install ntp

 

Centos

# sudo yum install ntp

After the installation, you can check the service will run at boot time by running:

# sudo /sbin/chkconfig ntpd on

 

Fedora/Rhel

# sudo yum install ntp

After the installation, you can check the service will run at boot time by running:

# sudo chkconfig ntpd on

Service Starting
Make sure that NTP is running fine after the installation.

# sudo /etc/init.d/ntp start

You can stop or restart the NTP service by running the following command

# sudo /etc/init.d/ntp stop

# sudo /etc/init.d/ntp restart

 

Once the installation has completed, go to official NTP Public Pool Time Servers, select your continent area where the server physically is located, then search for your country location and a list of NTP servers should appear.

NTP server setup

 

Edit the NTP daemon main configuration file /etc/ntp.conf comment the default list of Public Servers from pool.ntp.org project and replace it with the list provided by your country

For example,

#sever 0.centos.pool.ntp.org iburst

# sever 1.centos.pool.ntp.org iburst

Add like this,

server 0.ro.pool.ntp.org iburst

server 1.ro.pool.ntp.org iburst

 

If you need to allow clients from your networks to synchronize time with this server. You should make the changes in the NTP configuration like as given below:

restrict 192.168.1.0 netmask 255.255.255.0 nomodify notrap

The nomodify notrap means, your clients are not allowed to configure the server

 

Adding Firewall Rules

You can add firewall rule by using the following line:

# firewall-cmd –add-service=ntp –permanent

To obtain the effect of firewall rule you should reload the rule.

# firewall-cmd –reload

Start the NTP server

# systemctl start ntpd

# systemctl enable ntpd

Check the status of NTP service

# systemctl status ntpd

 

Verify the Time sync of server

Execute the following commands to verify NTP peers sync status and your system time.

# ntpq -p

# date –R

 

If you need any further help please do reach our support department at [email protected].

 

Was this article helpful?
Dislike 0
Views: 13