LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   How to synchronize time (https://www.linuxquestions.org/questions/ubuntu-63/how-to-synchronize-time-4175710378/)

PsychoHermit 04-03-2022 02:51 PM

How to synchronize time
 
Greetings folks,

My clock is off. I am running ubuntu 20.04.3 LTS. I installed systemd-timesyncd and opened port 37 udp and tcp. glenn@LinuxBox:~$ sudo timedatectl set-ntp on
How to make the time synchronize?

Code:

glenn@LinuxBox:~$ timedatectl
              Local time: Sun 2022-04-03 05:50:21 PDT   
          Universal time: Sun 2022-04-03 12:50:21 UTC   
                RTC time: Sun 2022-04-03 12:50:22       
                Time zone: America/Los_Angeles (PDT, -0700)
System clock synchronized: no                             
              NTP service: active                         
          RTC in local TZ: no

Thanks in advance.
--glenn

michaelk 04-03-2022 04:27 PM

There are several ways to synchronize time. I believe that Ubuntu uses systemd-timesyncd as its default time client which does not appear to be active. Check its status via the command:

sudo systemctl status systemd-timesyncd

wpeckham 04-03-2022 04:28 PM

After you have a NTP client running, you need to configure NTP to address NTPD servers!
To get a FAST sync, there is a command line to quickly sync it up, but the ntp client must not be running at the time. So check the man page and verify the command.
Start with the man page for systemd-timedated.service and you cannot go wrong.

(This was all a LOT easier before systemd, but it is still doable. Let us know if you get stuck.)

If it is running, stop it. run the sync command, then start the service and it should keep your clock spot on forever.

PsychoHermit 04-03-2022 04:40 PM

[code]
glenn@LinuxBox:~$ sudo systemctl status systemd-timesyncd
[sudo] password for glenn:
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; ve>
Active: active (running) since Sun 2022-04-03 03:58:42 PDT; 3h 36min ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 4991 (systemd-timesyn)
Status: "Idle."
Tasks: 2 (limit: 6087)
Memory: 1.3M
CGroup: /system.slice/systemd-timesyncd.service
└─4991 /lib/systemd/systemd-timesyncd

Apr 03 03:58:42 LinuxBox systemd[1]: Starting Network Time Synchronization...
Apr 03 03:58:42 LinuxBox systemd[1]: Started Network Time Synchronization.
glenn@LinuxBox:~$ man systemd.timedated.service
No manual entry for systemd.timedated.service
[code]

Still not synchronized.

Thanks,
--glenn

wpeckham 04-03-2022 04:44 PM

Quote:

Originally Posted by PsychoHermit (Post 6343718)
glenn@LinuxBox:~$ man systemd.timedated.service
No manual entry for systemd.timedated.service


Try
Code:

man systemd-timedated.service
"-" <> "."

michaelk 04-03-2022 05:16 PM

I would of expected an initial time sync message in the status that syncs to ntp.ubuntu.com

Post the contents of your /etc/systemd/timesyncd.conf file.
Are you using a VPN service?

PsychoHermit 04-03-2022 06:42 PM

Newbie here finding the man pages less than helpful. I don't have a clue.

Code:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
#NTP=
#FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

Thanks,
-glenn

michaelk 04-03-2022 06:52 PM

The default settings I guess are compiled into systemd. I would try uncommenting RootDistanceMaxSec and change it from 5 to 10 seconds and see what happens. And restart systemd-timesyncd

PsychoHermit 04-03-2022 08:49 PM

Set RootDistanceMaxSec to 10 and restarted systemd-timesyncd.

Code:

glenn@LinuxBox:~$ timedatectl
              Local time: Sun 2022-04-03 11:48:05 PDT   
          Universal time: Sun 2022-04-03 18:48:05 UTC   
                RTC time: Sun 2022-04-03 18:48:05       
                Time zone: America/Los_Angeles (PDT, -0700)
System clock synchronized: no                             
              NTP service: active                         
          RTC in local TZ: no

Thanks,
--glenn

michaelk 04-03-2022 09:24 PM

Check the status to see if it connected to a time server

It appears that your hardware clock is set for local time but your system thinks its UTC (RTC in local TZ: no).

PsychoHermit 04-04-2022 08:47 AM

I switched to chrony and it hooked right up and synchronized.

Thanks for the help,
--glenn


All times are GMT -5. The time now is 03:24 PM.