Setting up Network Time Protocol (NTP) on CentOS involves installing the NTP package, configuring it, and ensuring the service runs correctly.
1. Install the NTP Package:
sudo dnf install ntp
2. Configure NTP (Optional, for specific server pools or client restrictions):
Edit the NTP configuration file,
/etc/ntp.conf
, using a text editor like vi
or nano
.
sudo vi /etc/ntp.conf
- Specify NTP Servers: You can use the default
pool.ntp.org
servers or specify others. For example:
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
- Restrict Access (if setting up an NTP server): To allow specific clients to synchronize with your server, add
restrict
lines. For example, to allow clients from a specific subnet:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
3. Start and Enable the NTP Service:
sudo systemctl start ntpd
sudo systemctl enable ntpd
4. Adjust Firewall Rules (if Firewalld is active):
Allow NTP traffic through the firewall.
sudo firewall-cmd --add-service=ntp --permanent
sudo firewall-cmd --reload
5. Verify NTP Synchronization:
Check the synchronization status and peers.
ntpq -p
The output will show the NTP servers, their status, and synchronization details. A
*
next to a server indicates it is currently being used for synchronization.