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:

date

Example of setting the time zone:

cp /usr/share/zoneinfo/Europe/Kiev /etc/localtime

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:

server 0.ubuntu.pool.ntp.org
server 1.ubuntu.pool.ntp.org
...

We prohibit all access to the server:

restrict default ignore

Or we allow access from the internal network:

restrict 192.168.0.0 mask 255.255.255.0 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:
IPTables rules for NTP and SNTP

Подписаться на IT Blog (RU) по Email
Subscribe to IT Blog (EN) by Email

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a Reply