In this guide, we are going to learn how to configure NTP server using NTPd on Fedora 30. NTP server broadcasts date and time information in order to keep the time clocks on networked computer systems synchronized to a common reference over the network or the Internet.
Configure NTP Server using NTPd on Fedora 30
Disable Chrony
Chrony is another versatile implementation of the NTP that can be used as a replacement of the the default user space NTP daemon and is installed by default on Fedora 30.
rpm -qa | grep chrony
chrony-3.4-2.fc30.x86_64
Both Chrony Daemon (chronyd) and NTPd cannot run at the same time and hence stop and disable Chrony Daemon so as to use NTPd.
systemctl stop chronyd
systemctl disable chronyd
Install NTP Daemon (ntpd)
NTP daemon is provided by the ntp package which is available by default on Fedora 30 repos.
dnf install ntp
Configuring NTP on Fedora 30
The main configuration file for NTP is /etc/ntp.conf. Hence, to make configuration changes, open this file with your preferred editor.
vim /etc/ntp.conf
Configure Access Control to an NTP Service
The NTP daemon implements a general purpose address/mask based restriction list. Restriction can be implemented using the restrict command. The restrict command syntax is;
restrict address [mask mask] [other options]
To configure NTP to allow LAN systems to get time services from the NTP server, you need to define the network address as shown below.
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
- The
nomodify
options prevents any changes to the configuration. - The
notrap
option preventsntpdc
control message protocol traps.
You can read more about restrict and other command options on man ntp.conf.
Configure Public NTP Servers Entries
NTP is configured to use time servers from the Fedora pool by default. These servers are used for time synchronization. Hence, you can obtain a list of the servers on your timezone (or your Continent) from NTP Public Pool Time Servers and add them as shown below;
...
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.fedora.pool.ntp.org iburst
server 0.africa.pool.ntp.org iburst
server 1.africa.pool.ntp.org iburst
server 2.africa.pool.ntp.org iburst
server 3.africa.pool.ntp.org iburst
...
Configure the Firewall to Allow Incoming NTP Packets
The NTP
traffic consists of UDP
packets on port 123
. You need to permit traffic to this port through Firewalld.
firewall-cmd --add-port=123/udp --permanent
firewall-cmd --reload
Running NTPd
To start and enable NTPd to run on system boot, run the commands belows;
systemctl start ntpd
systemctl enable ntpd
Verify NTP
To verify if NTP server is working fine, try to list your NTP peers.
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp4.inx.net.za 0.60.139.194 2 u 55 64 27 197.626 -44.526 50.599
+102.130.49.223 85.199.214.98 2 u 58 64 37 197.764 -46.516 48.474
+helpdesk.digita 196.10.55.57 3 u 60 64 37 198.201 -7.566 35.213
196.9.24.88 146.64.8.7 2 u 70 64 16 160.210 -36.686 53.051
That seems fine. Proceed to configure NTP client.
Configuring NTP Client
Now that your NTP server is up and running, configure the NTP client to synchronize its time from your NTP server. In this guide, we are using Ubuntu 18.04 server as our NTP client. The configurations of the NTP client is mostly similar to the configuration of the NTP server.
Synchronize time manually using ntpdate
Run the command below to install ntpdate on Ubuntu 18.04
apt install ntpdate
To manually synchronize time with NTP server using ntpdate;
ntpdate 192.168.0.101
5 May 13:22:49 ntpdate[2831]: adjust time server 192.168.0.101 offset -0.025443 sec
Well, seems all is well with manual time synchronization.
Synchronize time automatically with NTP
Run the command below to install ntp;
apt install ntp
NTP service is set to run by default after installation on Ubuntu 18.04. To configure the NTP client to synchronize time from your NTP server, edit the ntp configuration file and replace the public NTP pool servers with your server.
vim /etc/ntp.conf
...
# Specify one or more NTP servers.
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
server 192.168.0.101 iburst
...
You can as well just add your server to the configuration file and make it the preferred reference clock. This can be achieved by the use of the prefer option.
server 192.168.0.101 prefer iburst
Save the configuration file and restart ntp. You also need to disable Systemd timesyncd ntp.
timedatectl set-ntp off
systemctl restart ntp
Verify time synchronization
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*192.168.0.101 196.9.24.88 3 u - 64 1 0.851 0.233 0.498
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
alphyn.canonica 194.58.203.20 2 u 5 64 1 294.794 -31.291 0.000
chilipepper.can 17.253.34.253 2 u 6 64 1 270.919 -50.307 0.000
pugot.canonical 145.238.203.14 2 u 4 64 1 264.920 -50.840 0.000
golem.canonical 145.238.203.14 2 u 3 64 1 274.537 -56.011 0.000
Enable NTP to run on system boot.
systemctl enable ntp
For the basic configurations, that is just it on how to configure NTP server using NTPd on Fedora 30.
Check our other guides on Fedora 30 by following the links below;
Install MariaDB 10.3 on Fedora 30