I have a raspberry pi I use for an irrigation system. The problem is it doesn't have hardware clock so, every time it reboots, the system time is wrong, and I cannot set it to sync it automatically.

I have discover that when the system time is wrong, dns requests doesn't work, so every time I try to send a request I just get:

[root@alarmpi me]# ntpdate 3.es.pool.ntp.org
Error resolving 3.es.pool.ntp.org: Name or service not known (-2)
12 Aug 15:37:15 ntpdate[2385]: Can't find host 3.es.pool.ntp.org: Name or service not known (-2)
12 Aug 15:37:15 ntpdate[2385]: no servers can be used, exiting

By the way I get the same connection errors if I try to use pacman, wget, python/requests, even ping... So it is a dns thing for sure.

[me@alarmpi ~]$ ping google.com
ping: google.com: Name or service not known

If I set the time and date manually, it works again, but I live 300km from where this thing is, and I can't do it manually every day there is a power cut.

[root@alarmpi me]# timedatectl
               Local time: Mon 2019-08-12 15:47:40 CEST
           Universal time: Mon 2019-08-12 13:47:40 UTC
                 RTC time: n/a
                Time zone: Europe/Madrid (CEST, +0200)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
[root@alarmpi me]# timedatectl set-ntp false
[root@alarmpi me]# timedatectl set-time "2019-08.13 10:45:45 CEST"
[root@alarmpi me]# ping google.com
PING google.com ( 56(84) bytes of data.
64 bytes from ( icmp_seq=1 ttl=54 time=22.7 ms
64 bytes from ( icmp_seq=2 ttl=54 time=31.6 ms
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 292ms
rtt min/avg/max/mdev = 22.739/27.161/31.583/4.422 ms

[root@alarmpi me]# ntpdate 3.es.pool.ntp.org
13 Aug 10:49:54 ntpdate[2498]: adjust time server offset 0.004894 sec

So I'm a little lost here. How can I sync the clock automatically if it doesn't let me connect to the service because I'm out of sync?


Some NTP servers listen directly on IP addresses and advertise themselves as such. For instance, NIST provides IPs for each of their NTP servers, so you can pick one and do ntpdate <IP> on init. This won't need DNS resolution and should work right away.

Alternatively, you can also try to use the fake-hwclock package, which preserves the approximate time between reboots. It's not perfect and does not provide the accurate time, but it might be enough to resolve the domain names for NTP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.