Categories
Apache HTTP Concepts Internet linux Microsoft

How to sync server time with Network Time Protocol server

Sync server time on Linux with NTP

What is NTP?

An Internet protocol is used to synchronise clocks of computers, for instance linux server. This protocol is known as NTP (Network Time Protocol).

Following steps shows how to sync time using the terminal. Before we start login to the server via terminal and follow the steps given below.

Step 1: Check whether NTP is installed

Use the ntpstat command to view the status of the NTP service on the instance. It may happen that you get an error message prompting that NTP is not installed. In that case you have to install it on the server.

# sudo ntpstat
-bash: ntpstat: command not found

Step 2: Install NTP

Use the following command to install NTP on server.

# sudo yum install ntp

Step 3: Start NTP

After the installation is complete we need to start NTP by using the following command.

# sudo systemctl start ntpd

Note!

Enable NTP to start at boot:

# sudo systemctl enable ntpd

Stop NTP:

# sudo systemctl stop ntpd

Restart NTP:

# sudo systemctl restart ntpd

Step 4: Sync Time

For this use the following command.

# sudo ntpdate -q 0.rhel.pool.ntp.org

And restart NTP

# sudo systemctl restart ntpd

…and the server time will be synced.

Sync server time on Windows with SNTP

What is SNTP?

Simple Network Time Protocol (SNTP) is a simplified version of Network Time Protocol (NTP).  This is used to synchronize computer clocks on a network. As name defines simplified version of NTP is generally used when full implementation of NTP is not needed.

SNTP is a simplified access strategy for servers and clients using NTP. This simplified protocol is widely used to synchronizes a computer’s system time with a server that has already been synchronized by a source such as a radio, satellite receiver or modem. 

Interestingly, SNTP supports unicast, multicast and anycast operating modes. In unicast mode, the client sends a request to a dedicated server by referencing its unicast address. Once a reply is received from the server, the client determines the time, roundtrip delay and local clock offset in reference to the server. In multicast mode, the server sends an unsolicited message to a dedicated IPv4 or IPv6 local broadcast address. Generally, a multicast client does not send any requests to the service because of the service disruption caused by unknown and untrusted multicast servers. The disruption can be avoided through an access control mechanism that allows a client to select a designated server he or she knows and trusts.

Use below code to sync server time on windows machine

@echo on & @setlocal enableextensions

@echo =========================
@echo Turn off the time service
net stop w32time

@echo =========================
@echo Set the SNTP (Simple Network Time Protocol) source for the time server

w32tm /config /syncfromflags:manual /manualpeerlist:"0.it.pool.ntp.org 1.it.pool.ntp.org 2.it.pool.ntp.org 3.it.pool.ntp.org"

@echo =========================
@echo ... and then turn on the time service back on

net start w32time

@echo =========================
@echo Tell the time sync service to use the changes

w32tm /config /update

@echo =========================
@echo Reset the local computer's time against the time server

w32tm /resync /rediscover

@endlocal & @goto :EOF
'Coz sharing is caring

By Swatantra Kumar

Swatantra is an engineering leader with a successful record in building, nurturing, managing, and leading a multi-disciplinary, diverse, and distributed team of engineers and managers developing and delivering solutions. Professionally, he oversees solution design-development-delivery, cloud transition, IT strategies, technical and organizational leadership, TOM, IT governance, digital transformation, Innovation, stakeholder management, management consulting, and technology vision & strategy. When he's not working, he enjoys reading about and working with new technologies, and trying to get his friends to make the move to new web trends. He has written, co-written, and published many articles in international journals, on various domains/topics including Open Source, Networks, Low-Code, Mobile Technologies, and Business Intelligence. He made a proposal for an information management system at the University level during his graduation days.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.