Synchronize Linux System Clock to Windows Ntp Service

How do I synchronize clocks between Linux and Windows?

Make both machines be NTP clients. That should make their clocks correct to within a rather short interval, and is already developed, tested, and available.

According to the Wikipedia page on NTP, you should expect around 10 ms over Internet, far less if you have a local time server on your LAN, which should be quite easy to set up.

how to sync windows time from a ntp time server in command

Use net time
net time \\timesrv /set /yes

after your comment try this one in evelated prompt :

w32tm /config /update /manualpeerlist:yourtimerserver

How to sync time between windows and linux computers?

You can set up a NTP Server on one of the Linux machines and have the others point to it.

  • How to setup a NTP-Server with Redhat

Connect to the NTP-Server in Redhat:

  • ntpdate -du ntpservername

Connect to the NTP-Server in Windows XP:

  • Right click on the clock in the system tray
  • Choose adjust time
  • On the internet time tab insert your server hostname

WSL2 Clock is out of sync with Windows

UPDATE: as mentioned by drkvogel, the Clock Sync fix was released in WSL2 kernel version 5.10.16.3


OBSOLETE

At time of writing, this GitHub Issue was open for the bug.

The workaround I chose for my situation (single distro in WSL2) is to use Windows Task Scheduler to run hwclock in WSL whenever Windows resyncs hardware clock.

Windows: Open PowerShell as Administrator

schtasks /create /tn WSLClockSync /tr "wsl.exe sudo hwclock -s" /sc onevent /ec system /mo "*[System[Provider[@Name='Microsoft-Windows-Kernel-General'] and (EventID=1)]]"
Set-ScheduledTask WSLClockSync -Settings (New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries)

WSL2: Run sudo visudo and add hwclock to sudoers to skip password prompt

# bottom of my file looks like this
...
...
#includedir /etc/sudoers.d
<username> ALL=(ALL) NOPASSWD:/usr/sbin/hwclock, /usr/bin/apt update, /usr/bin/apt upgrade

Results

illustration showing Windows clock and WSL clock in sync

See image for how to get Event XPath from Windows Event filtering. Use as provided to let task scheduler auto-display scheduled triggers.

illustration showing scheduled task created



Related Topics



Leave a reply



Submit