To configure an NTP client and server on CentOS or Red Hat Linux, follow these steps:
- Install the NTP package on the server:
sudo yum install ntp
- Edit the NTP configuration file
/etc/ntp.conf
:sudo nano /etc/ntp.conf
- In the
server
section, add one or more NTP servers that the client should synchronize with. For example, to synchronize with the NTP pool servers, add the following lines:server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
server 3.centos.pool.ntp.org
You can also specify your own NTP server, if you have one.
- Save and exit the file.
- Start the NTP service:
sudo systemctl start ntpd
- Enable the NTP service to start automatically at boot time:
sudo systemctl enable ntpd
- To verify that the client is synchronizing with the NTP server, use the
ntpq
command:ntpq -p
This will show a list of the NTP servers that the client is synchronizing with, along with their status and the current offset.
To configure an NTP server, follow these additional steps:
- Edit the NTP configuration file
/etc/ntp.conf
:sudo nano /etc/ntp.conf
- In the
server
section, add theiburst
option to the server line to improve synchronization speed:server 127.127.1.0 iburst
This specifies that the local clock should be used as a reference clock.
- Save and exit the file.
- Start the NTP service:
sudo systemctl start ntpd
- Enable the NTP service to start automatically at boot time:
sudo systemctl enable ntpd
That’s it! You have now configured an NTP client and server on CentOS or Red Hat Linux. Note that the client and server can be the same machine, in which case it will synchronize with itself.