I have a laptop running a version of Linux ( 3.12 ). I have ntpd installed and configured to sync with time.google.com. The problem I am having is if I am plugged into a network that only provides an IPV4 address, ntp's dns is using the ipv6 address:

    root@Node00b01973d6cc:~# ntpq -pn                                                                                           
     remote           refid      st t when poll reach   delay   offset  jitter                                              
==============================================================================                                           .LOCL.          10 l    7   64    1    0.000    0.000   0.002                                              
 ff0e::101       .MCST.          16 M    -   64    0    0.000    0.000   0.002                                              
 2001:4860:4806: .INIT.          16 u    -   64    0    0.000    0.000   0.000  

Now, if I force ntpd to use only ipv4 DNS with the -4 option, everything works fine

root@Node00b01973d6cc:~# ntpq -pn                                                                             
     remote           refid      st t when poll reach   delay   offset  jitter                                              
==============================================================================                                           .LOCL.          10 l   60   64    1    0.000    0.000   0.002                                         .GOOG.           1 u   57   64    1   29.278  341.883   0.002     

But I don't want to do this because if I go to a network that only gives ipv6 addresses this will fail. Is there a way to configure ntp to only use ipv4 ( or ipv6 ) if my interface actually has an ip address in that family?

The version of ntpd is 4.2.8p12. This is the ntp.conf file:

tinker panic 0                                                              

driftfile /usr/local/etc/ntp.drift                                          
disable auth                                                                   

# Update the realtime clock and override its default                         
# stratum of 0.                                                                   
server time.google.com prefer #Real Time Clock                             
server #Real Time Clock                           
server #Real Time Clock                                         
fudge stratum 10                                      
broadcast ff0e::101 iburst ttl 7              

I have figured out the root cause of why this started to happen. I recently disabled ipv6 forwarding on my system. Once I turn ipv6 forwarding back on, ntp starts using the ipv4 address as I would expect.

Why would turning on ipv6 forwarding do this?

By default the system boots with ipv6 forwarding disabled. To turn it on, in one of the boot scripts I have the line:

sysctl -w net.ipv6.conf.all.forwarding=1
  • I don't know. I notice on my Fedora 29 system that getent hosts time.google.com returns IPv6 only, even though I do not have ipv6 access, but getent ahosts time.google.com returns all results in the correct preference order. So I tried enabling ipv6 forwarding at runtime, both in conf.all and in conf.wlp2s0, but it did not change the result of getent hosts time.google.com – sourcejedi Apr 6 at 20:08
  • To gain a working configuration, I guess you could try an ugly hack with two separate server lines. server -4 time.google.com and server -6 time.google.com. – sourcejedi Apr 6 at 20:09

Your Answer

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

Browse other questions tagged or ask your own question.