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                                              
==============================================================================                                              
 127.127.1.0     .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 172.16.17.111                                                                             
     remote           refid      st t when poll reach   delay   offset  jitter                                              
==============================================================================                                              
 127.127.1.0     .LOCL.          10 l   60   64    1    0.000    0.000   0.002                                              
 216.239.35.12   .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 127.127.1.0 #Real Time Clock                           
server 127.127.1.0 #Real Time Clock                                         
fudge 127.127.1.0 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



getent hosts time.google.comreturns IPv6 only, even though I do not have ipv6 access, butgetent ahosts time.google.comreturns all results in the correct preference order. So I tried enabling ipv6 forwarding at runtime, both inconf.alland inconf.wlp2s0, but it did not change the result ofgetent hosts time.google.comserver -4 time.google.comandserver -6 time.google.com.wgetto download files, but they vanished in the meantime. My guess is that a nameserver when queried via IPv4 should answer with IPv4 addresses first, and when queried via IPv6, it should respond with IPv6 addresses first. In the pastwgethad tried to use IPv6, but could not connect; I had to specify the IPv4 address directly instead of the hostname to make it work.