Linux – How to fix time in Arch Linux

arch linuxdateterminaltime

I am currently using Arch Linux as my OS on my desktop. When I look at my time, it is 22:38, when the time clearly is around 17:08. When I invoke the command timedatectl, I get:

Local time: Wed 2017-01-11 22:37:43 IST
Universal time: Wed 2017-01-11 17:07:43 UTC
    RTC time: Wed 2017-01-11 17:07:41
    Time zone: Asia/Kolkata (IST, +0530)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

Update

When I run sudo systemctl status systemd-timesyncd, I get:

● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-01-11 00:49:36 IST; 1 day 1h ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 31123 (systemd-timesyn)
   Status: "Idle."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/systemd-timesyncd.service
           └─31123 /usr/lib/systemd/systemd-timesyncd

Jan 12 01:39:42 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 5.9.78.71:123 (1.arch.pool.ntp.org).
Jan 12 01:39:53 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 192.53.103.108:123 (1.arch.pool.ntp.org).
Jan 12 01:40:03 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.19.184:123 (2.arch.pool.ntp.org).
Jan 12 01:40:13 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.45.40:123 (2.arch.pool.ntp.org).
Jan 12 01:40:24 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 123.108.200.124:123 (2.arch.pool.ntp.org).
Jan 12 01:40:34 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 125.62.193.121:123 (2.arch.pool.ntp.org).
Jan 12 01:40:44 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.45.40:123 (3.arch.pool.ntp.org).
Jan 12 01:40:55 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 123.108.200.124:123 (3.arch.pool.ntp.org).
Jan 12 01:41:05 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.19.184:123 (3.arch.pool.ntp.org).
Jan 12 01:41:15 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 125.62.193.121:123 (3.arch.pool.ntp.org).

traceroute

I also tried the command traceroute -U -p ntp pool.ntp.org, and I get:

traceroute to pool.ntp.org (139.59.19.184), 30 hops max, 60 byte packets
 1  10.114.1.1 (10.114.1.1)  1.713 ms  2.020 ms  2.343 ms
 2  10.10.2.41 (10.10.2.41)  1.123 ms  2.580 ms  2.836 ms
 3  cyberoam.iisc.ac.in (10.10.1.98)  0.553 ms  0.806 ms  0.813 ms
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

How do I fix this? I've even tried timedatectl set-ntp true. Am I supposed to reboot for this to take effect?

Best Answer

systemd-timesyncd will not require you to reboot. I've tested timedatectl on my system. It might be necessary to wait a minute for a connection.

man timedatectl

status

Show current settings of the system clock and RTC, including whether network time synchronization is on. Note that whether network time synchronization is on simply reflects whether the systemd-timesyncd.service unit is enabled. Even if this command shows the status as off, a different service might still synchronize the clock with the network.

$ timedatectl status
      Local time: Wed 2017-01-11 13:45:07 GMT
  Universal time: Wed 2017-01-11 13:45:07 UTC
        RTC time: Wed 2017-01-11 13:45:07
       Time zone: Europe/London (GMT, +0000)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: yes

timedatectl manpage is lying on my system. Possibly the implementation was patched by Fedora, without patching the manpage. I do not know how to query which service is used; my system happens to use chronyd. I imagine it might also be possible to use ntp/ntpd.

However in your case I would be quite confident that Arch uses the upstream default of timesyncd.

$ systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; disabled; 
   Active: inactive (dead)
     Docs: man:systemd-timesyncd.service(8)

$ systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor pres
   Active: active (running) since Mon 2017-01-09 19:09:39 GMT; 1 day 18h ago
 Main PID: 928 (chronyd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/chronyd.service
           └─928 /usr/sbin/chronyd

You might have errors logged underneath the status. Make sure to run systemctl as a user with access to the system journal, e.g. using sudo.

Unlike chronyd with chronyc, there is no documented way to additionally query systemd-timesyncd for... anything really, beyond "NTP synchronized: no". Hope it has useful logs!

I suggest aiming to

  1. Identify which well-known pool.ntp.org alias your system is trying to use.
  2. Test the alias e.g. ntpdate -q arch.pool.ntp.org.
  3. traceroute to the alias to see if there is a nearby block i.e. a firewall preventing access. As always, I would use ping first because it gets results quicker (and is less prone to mis-interpretation), or use the mtr version of traceroute (this also defaults to ICMP traceroute, which avoids lots of output from multi-path networks). Ultimately you want something like traceroute -U -p ntp pool.ntp.org, i.e. using the same UDP port as NTP does.

EDIT: previous versions of this answer were confused about systemd-timesyncd's default NTP servers. Although they are commented out (disabled) in timesyncd.conf, it should only be necessary to uncomment the line if you need to change the server. The default values are built in to timesyncd at compile time. This is mentioned in all documentation.

https://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/

https://wiki.archlinux.org/index.php/Systemd-timesyncd

Related Question