How to Configure NTP in Linux Operating Systems?

How to Configure NTP in Linux Operating Systems?

What is NTP?

An abbreviation for “ NTP Network Time Protocol”. NTP is a protocol used to synchronize the clocks of computers on packet-switched networks with variable latency. The protocol is specifically designed to be resistant to the effects of variable delay, thanks to the use of jitter buffers. NTP is one of the oldest Internet protocols still in use. NTP uses the User Datagram Protocol (UDP) over port 123. NTP settings are made from either the  /etc/ntp.conf or /etc/xntp.conf file, depending on which Linux distribution is used.

Now let’s move on to our configuration. We will examine our configuration under two headings, “NTP Client and “NTP Server“. We will also examine the configuration for the “Oracle Real Application Cluster” environments.

NTP Client

1. We log in to our server with the “root” user and install our NTP package.

# yum install ntp

2. We are starting the NTP Service on our server and at the same time, we are making the necessary configuration for it to start automatically when our server starts up.

# service ntpd start
# chkconfig ntpd on

3. If we are going to make any configuration in our NTP service, we do it in the “/etc/ntp.conf” file.

# vim /etc/ntp.conf

4. If we change any settings in this file, we must restart the NTP Service.

# service ntpd restart

5. If our Firewall is open, we need to make the necessary adjustments in the Firewall service so that our NTP service can work. If our Firewall service is turned off, we can skip this step.

# iptables -A INPUT -p udp --dport 123 -j ACCEPT

A-) Let’s Configure NTP Client

1. We add the addresses of our time servers in the NTP configuration file “/etc/ntp.conf”.

# vim /etc/ntp.conf
-- Opening the file. We find the line below and add our servers.
If we are going to add a time server located in our local network, we must add it with the "ibtrust" "parameter at the end as follows.

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server koraykey-ntp.koraykey.com iburst
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org

2. After making these changes, we restart our service for the settings to take effect.

# service ntpd restart
Shutting down ntpd: [  OK  ]
Starting ntpd: [  OK  ]

3. We can check the accuracy or availability of our server by querying the time of our local network environment or other server.

# ntpdate -u 0.koraykey-ntp.koraykey.com
31 Mar 22:59:23 ntpdate[3331]: adjust time server 192.168.2.1 offset -0.001525 sec

B-) NTP Server Configuration

1. If we want to configure our server to provide NTP Server service, we must make the necessary arrangements in the “/etc/ntp.conf” file after the above installation steps. In order for our server to update its own date and time, it must be able to access servers on the internet. Otherwise, we have to manually adjust the settings of our server ourselves. In addition, security settings must be made in order for our server to serve computers on the local network.

# vim /etc/ntp.conf

-- Opening the file. We find the following line and edit our local network information.
Thus, we ensure that our computers in the local network can receive NTP service from our server.

# Hosts on local network are less restricted.
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap

2. After making these changes, we restart our service for the settings to take effect.

# service ntpd restart
Shutting down ntpd: [  OK  ]
Starting ntpd: [  OK  ]

Configuring “Oracle Real Application Cluster” Builds

1. If we are going to use “Oracle Cluster Time Synchronization” instead of “NTP” for time synchronization in Oracle Real Application Cluster installation, we should make our settings as follows to turn off the NTP service.

We are shutting down our NTP Service.
# service ntpd stop
Shutting down ntpd: [ OK ]

Our NTP Service is automatic as our server restarts.
We are closing our service so that it does not open.

# chkconfig ntpd off

We rename our NTP configuration file with another name.

# mv /etc/ntp.conf /etc/ntp.conf.org

We are deleting the ntpd.pid file.

# rm /var/run/ntpd.pid

2. If we are going to use the “NTP” service for time synchronization in the Oracle Real Application Cluster installation, we should make our settings as follows.

-- We configure the synchronization setting of our time service.

# vim /etc/sysconfig/ntpd
-- Configure the file as follows.

OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"

-- For our settings to take effect
# service ntpd restart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]

The steps applied here have been tested on the “Oracle Enterprise Linux 6.4” operating system. It is also compatible with other Linux distributions.

I hope it was a useful article.