How To Install And Configure NTP Server And NTP Client In Linux?
======
You might heard this word many times and also you might had worked on this.
However, i will tell you clearly in this article about NTP Server setup and NTP Client setup
We will see about **[Chrony NTP Client setup][1]** later.
### What Is NTP Server?
NTP stands for Network Time Protocol.
It is a networking protocol that synchronize the clock between computer systems over the network.
In other hand I can say. It will keep the same time (It keep an accurate time) to all the systems which are connected to NTP server through NTP or Chrony client.
NTP can usually maintain time to within tens of milliseconds over the public Internet, and can achieve better than one millisecond accuracy in local area networks under ideal conditions.
It uses User Datagram Protocol (UDP) on port number 123 for send and receive timestamps. It’s a client/server application.
It send and receive timestamps using the User Datagram Protocol (UDP) on port number 123.
### What Is NTP Client?
NTP client will synchronize its clock to the network time server.
### What Is Chrony Client?
Chrony is replacement of NTP client. It can synchronize the system clock faster with better time accuracy and it can be particularly useful for the systems which are not online all the time.
### Why We Need NTP Server?
To keep all the servers in your organization in-sync with an accurate time to perform time based jobs.
To clarify this, I will tell you a scenario. Say for example, we have two servers (Server1 and Server2). The server1 usually complete the batch jobs at 10:55 then the server2 needs to run another job at 11:00 based on the server1 job completion report.
If both the system is using in a different time (if one system is ahead of the others, the others are behind that particular one) then we can’t perform this. To achieve this, we should setup NTP. Hope it cleared your doubts about NTP.
In this article, we are going to use the following setup to test this.
### NTP SERVER SIDE: How To Install NTP Server In Linux?
There is no different packages for NTP server and NTP client since it’s a client/server model. The NTP package is available in distribution official repository so, use the distribution package manger to install it.
For **`Fedora`** system, use **[DNF Command][2]** to install ntp.
```
$ sudo dnf install ntp
```
For **`Debian/Ubuntu`** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install ntp.
```
$ sudo apt install ntp
```
For **`Arch Linux`** based systems, use **[Pacman Command][5]** to install ntp.
```
$ sudo pacman -S ntp
```
For **`RHEL/CentOS`** systems, use **[YUM Command][6]** to install ntp.
```
$ sudo yum install ntp
```
For **`openSUSE Leap`** system, use **[Zypper Command][7]** to install ntp.
```
$ sudo zypper install ntp
```
### How To Configure The NTP Server In Linux?
Once you have installed the NTP package, make sure you have to uncomment the following configuration in the `/etc/ntp.conf` file on server side.
By default the NTP server configuration relies on `X.distribution_name.pool.ntp.org`. If you want you can use the default configuration or you can change it as per your location (country specific) by visiting <https://www.ntppool.org/zone/@> site.
Say for example. If you are in India then your NTP server will be `0.in.pool.ntp.org` and it will work for most of the countries.
```
# vi /etc/ntp.conf
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
*CentOS7.2daygee 133.243.238.163 2 u 14 64 37 0.686 0.151 16.432
```
Run the following command to get the current status of ntpd.
```
# ntpstat
synchronised to NTP server (192.168.1.8) at stratum 3
time correct to within 508 ms
polling server every 64 s
```
Finally run the `date` command.
```
# date
Tue Mar 26 23:17:05 CDT 2019
```
If you are observing a significant offset in the NTP output. Run the following command to sync clock manually from the NTP server. Make sure that your NTP client should be inactive state when you perform the command.