Configuring NTP Client and NTP Server in Linux

NTP (Network Time Protocol)
Uses UDP connections and port 123.

Example installation in Ubuntu/Debian:

sudo apt-get install ntp

The current date can be viewed by the command:


Example of setting the time zone:

cp /usr/share/zoneinfo/Europe/Kiev /etc/localtime
timedatectl list-timezones
timedatectl list-timezones | grep -i europe
timedatectl set-timezone Europe/Kiev

Setting hours and minutes:

date -s 10:18
date --set 10:18

Example of full time setting (without spaces, in digital form):

date monthdayhourminuteyear.second

Checking the time server:

ntpdate -q SERVER

View status:

sudo ntpq -p
ntpq -c peers

Let’s start editing the configuration file /etc/ntp.conf.

A few lines:
Specify the server with which to compare the time:


We prohibit all access to the server:

restrict default ignore

Or we allow access from the internal network:

restrict mask nomodify notrap

Restart ntp to make the changes in the configuration file take effect:

sudo service ntp restart

An example of time synchronization from the Windows command line with a Linux server:

net time \\SERVER /set /yes

See also my articles:
IPTables rules for NTP and SNTP
Time sync on Ubuntu 18.04

Leave a comment

Leave a Reply