# ntp-client does not sync the clock because DNS missing boot

## Roman_Gruber

Can someone give me a hint / fix on how to fix the ntp-client startup script please?

I prefer a fix when my dns / ip-address gets renewed / changed everytime ntp-client is run after maybe ping to the ntp-client succeeded.

Wish: Ntp-client checks for a valid internet connection, syncs the clock once, sets the hwclock, after it has finished, it stops itself and frees the used up memory. @ every boot of the box.

Sorry for the rant, a bit detail explanation with my personal opinion.

```
ASUS-G75VW roman # /etc/init.d/ntp-client restart

 * Setting clock via the NTP client 'ntpdate' ...                                                                                                                     [ ok ]

ASUS-G75VW roman # uptime

 12:13:04 up  2:38,  3 users,  load average: 0,49, 0,62, 0,65

```

I assume when I have read it correctly, that my box was over 2 hours 38 min awake and the clock was still not corrected?

My notebook is connected via wireless lan to my adsl modem. Because of some delays during bootup and there are no valid dns, the ntp-client shipped script fails and do not attempt to resync

Gentoo wiki recommendations are also not working, basically useless

 *Quote:*   

> ASUS-G75VW roman # cat /etc/ntp.conf 
> 
> # NOTES:
> 
> # DHCP clients can append or replace NTP configuration files.
> ...

 

```
ASUS-G75VW roman # qlist -Iv net-misc/ntp

net-misc/ntp-4.2.8_p8

ASUS-G75VW roman # rc-update show|grep ntp

           ntp-client |      default                                  

ASUS-G75VW roman # emerge -pv ntp

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R    ] net-misc/ntp-4.2.8_p8::gentoo  USE="ssl threads -caps -debug -ipv6 -libressl -openntpd -parse-clocks -readline -samba (-selinux) -snmp -vim-syntax -zeroconf" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

ASUS-G75VW roman # 

```

What annoys me is: I have set the ntp-client in my default runlevel. I would expect that the shipped scripts would at least force ntp-client to sync, and when the dns, lets rephrase it more easily, when my ip address / mask whatever ... is changed ntp is also forced. 

It is definitely not.

In my eyes it is broken, but I am quite sure some will tell me, its my setup, whatever.

In short, ntp does not sync itself. Regardless fora  reasonable time 2.5 hours is a reasonable time.

--

I have also an issue with dhcp because it overwrote my resolv.conf. I fixed that with setting the i flag wth chattr on resolv.conf

--

I also do not get the point when I add a service to rc-update, it should at least do something or work.

snip from messages after i manually restarted the service

 *Quote:*   

> Jul 13 12:12:52 ASUS-G75VW ntpdate[9380]: step time server 131.130.251.107 offset 269.999538 sec
> 
> 

 

I have no idea why my notebook, whcih is always on the juice, battery or ac-power, it has always juice, has such a drift for a few months. ...

--

I remember when I used windows, 10 years ago, those time server forced to correct the hwclock.

hwclock tells me the time of my box.

Why can not we have that feature on, as in windows, to correct the hardware clock too?

--

I am qutie sure these issues do not exists on bigger networks, where you have 24h / 7 days a week a server alive and therfore you always have a valid dns with valid ntp server running. For lets call it dial up connections, could be when you are not picky, the provided shipped script is useless.

e.g.

https://forums.gentoo.org/viewtopic-p-6182060.html?sid=8ff21b26d91087f4ffe3f2a806993b3f

 *Quote:*   

> From my point of view it seems like the wireless connection isn't established in time during boot and ntp-client runs into timeout. How could I change the timeout setting of ntp-client?

 

...

I have not dug deeper, there were a few other posts.

In short known issue. I want a proper fix, not a hack

----------

## Syl20

I don't really understand what you want...

The ntp-client "service" (I don't think it is) just calls ntpdate, and exits. Period. rc-status shows it stopped. That means the clock is only synced once, on boot. To keep your clock synced everytime, you should enable the ntpd service, or add a ntpdate cron job.

If you want to sync your hardware clock, have a look on /etc/conf.d/hwclock.

If you need more features, perhaps it's time to write your own startup script ?

----------

## NeddySeagoon

tw04l124,

 *Quote:*   

> I have also an issue with dhcp because it overwrote my resolv.conf. I fixed that with setting the i flag wth chattr on resolv.conf

 

That works but its not the way dhcpcd is designed to operate.

By design, dhcpcd does everything it possibly can automatically.

It has a set of no* flags to turn off individual things you would rather manage yourself.   The man page is worth a read but less /usr/share/doc/netifrc-0.3.1/net.example.bz2

is a better source of information as its full of examples.

Things that need networking will not start until networking is considered to be 'up'.  What that means is user definable.

See  /etc/rc.conf.

You will nee do do some reading, or some trial and error,  as some versions of openrc include the lo interface and some don't.

If lo.net alone satisfies what is needed for networking to be considered 'up' then ntp-client will fail.

As others have pointed out, ntp-client is run once, to do a large step correction to the system time, ntpd fine tunes the clock on a regular basis to keep it correct. 

You may need both.  ntpd will exit if the error is bigger that about 20 min.

----------

## Roman_Gruber

 *Syl20 wrote:*   

> 
> 
> The ntp-client "service" (I don't think it is) just calls ntpdate, and exits. Period. rc-status shows it stopped. That means the clock is only synced once, on boot. To keep your clock synced everytime, you should enable the ntpd service, or add a ntpdate cron job.
> 
> 

 

Exactly. Gentoo shipped script is broken by design.

restart or start of the script seems to just run once and not keep it as deamon which i expect from ntp service.

I think I already stated enough already why it is broken

Script does not check for availability of the network. Means the outside is reachable. E.g. check with ping 4.4.4.4 or the ntp server itself.

SCript does not invoke itself after the network node is changed. Means changed settings to the network adapter

--

What I mean was to state why I think the shipped script is crap, not well designed. And I tried to explain it with my own words and give examples why.

--

I tried the other ntp pacakges which are in the tree, but they do exactly nothing.

I am not in the mood, becuase some idiotic programmer thought of so many possibliites. to read tons of man-pages and fiddle around with config files, to just sync the clock.

EAsy workaround as of now

```
 /etc/init.d/ntp-client restart;emerge --sync;emerge -av --update --keep-going --deep -N world

```

Which is enough because the box should be updated anyway regularly. 

And no I am not a friend of aliases. I want to see what is done 

--

Regarding windows 98, at least for sure windows 2000, was able to correct the hardware clock, sync the clock itself without much intervention.

--

Expected behaviour:

when the service is added to a rc runlevel. it should correct the clock and the hardware clock itself when the network node is changed. It does not hurt to sync the clock when the network address is renewed by e.g. dhcpcd, the user, ... ...

----------

## Jaglover

AFAIK net-misc/ntp provides both, ntp-client and ntpd. The first one corrects the clock at startup and exits, the second one keeps the clock correct. It is up to you to set it up properly.

----------

## Roman_Gruber

 *NeddySeagoon wrote:*   

> tw04l124,
> 
>  *Quote:*   I have also an issue with dhcp because it overwrote my resolv.conf. I fixed that with setting the i flag wth chattr on resolv.conf 
> 
> That works but its not the way dhcpcd is designed to operate.
> ...

 

It is broken by design too, or I was just unable to find a way after reading pages over pages on how to get dhcpcd working.

The provided dns servers from the adsl2 modem are just unresponsive. WEbpages opens with a big delay in any browser installed. Its a DNS issue, because the DNS server can not handle the requrest in a timely fashion. 

```
ASUS-G75VW roman # equery y dhcpcd

Keywords for net-misc/dhcpcd:

             |                                 |   u   |  

             | a a         p s     a   n r     |   n   |  

             | l m   h i   p p   m r m i i s   | e u s | r

             | p d a p a p c a x i m 6 o s 3   | a s l | e

             | h 6 r p 6 p 6 r 8 p 6 8 s c 9 s | p e o | p

             | a 4 m a 4 c 4 c 6 s 4 k 2 v 0 h | i d t | o

-------------+---------------------------------+-------+-------

   6.10.1    | + + + + + + + + + ~ ~ o o o ~ ~ | 5 o 0 | gentoo

   6.10.2    | ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ o o o ~ ~ | 6 #   | gentoo

[I]6.10.3    | ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ o o o ~ ~ | 6 #   | gentoo

   6.11.0    | ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ o o o ~ ~ | 6 #   | gentoo

   6.11.1    | ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ o o o ~ ~ | 6 #   | gentoo

   6.11.1-r1 | ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ o o o ~ ~ | 6 o   | gentoo

     9999    | o o o o o o o o o o o o o o o o | 6 o   | gentoo

```

Sadly any higher dhcpcd breaks functionality. 

Means:

I install a higher dhcpcd, and the old config and the new config does not work anymore.

No DNS Aquired from MY ADSL2 modem, no wifi network stuff exchanged via wpa_supplicant and dns and ADSL2 modem.

workaround: 

hardmask it.

---

I try to keep the technical aspects as much out as possible. Else some smart guy will show up and tells me how stuff works because its his profession (I think about 4-5 guys here ..).

I am well aware what DNS / DHCP and other stuff does, in the principles. Thats enough to understand the principles. I am not interested in knowing the full details of any software piece out there in the world. That is not my scope.

--

Summary / Expected behaviour

eudev + newest dhcpcd in portage tree + wpa_supplicant + ADSL2 modem with wifi functionality

Consider custom dns servers provided with /etc/resolv.conf as it used to be in the old days, and possible too

aquire network node data to be able to establish a successful connection with the www

(aquire ip adress somewhere in 10.0.0.x range, subnetmask, gateway, establish encrypted wifi connection with wpa_supplicant; works well with eudev)

withlist: sync the node time; should be all the duty of the service called net or network of rc-update

----------

## Roman_Gruber

 *Jaglover wrote:*   

> AFAIK net-misc/ntp provides both, ntp-client and ntpd. The first one corrects the clock at startup and exits, the second one keeps the clock correct. It is up to you to set it up properly.

 

Agree

```
^[[AJul 23 14:56:08 ASUS-G75VW ntpd[21811]: ntpd 4.2.8p8@1.3265-o Mon Jul 11 16:28:49 UTC 2016 (1): Starting

Jul 23 14:56:08 ASUS-G75VW ntpd[21811]: Command line: /usr/sbin/ntpd -p /var/run/ntpd.pid -g

Jul 23 14:56:08 ASUS-G75VW ntpd[21814]: proto: precision = 0.108 usec (-23)

Jul 23 14:56:08 ASUS-G75VW ntpd[21814]: restrict: ignoring line 47, address/host '[::1]' unusable.

Jul 23 14:56:08 ASUS-G75VW ntpd[21814]: restrict: 'monitor' cannot be disabled while 'limited' is enabled

Jul 23 14:56:08 ASUS-G75VW ntpd[21814]: Listen and drop on 0 v4wildcard 0.0.0.0:123

Jul 23 14:56:08 ASUS-G75VW ntpd[21814]: Listen normally on 1 lo 127.0.0.1:123

Jul 23 14:56:08 ASUS-G75VW ntpd[21814]: Listen normally on 2 wlan0 10.0.0.2:123

Jul 23 14:56:08 ASUS-G75VW ntpd[21814]: Listening on routing socket on fd #19 for interface updates

```

```
ASUS-G75VW roman # /etc/init.d/ntpd start

 * Starting ntpd ...    
```

Seems my fault to comprehend. 

MAkes sense now, but ntp-client should not be able to be added to rc-update 

ntp-client restart / start should point to ntpd

Of course the unix guys will say, look deamon => ntp daemon => ntpd => should be used, thats it, its obvious now

client ... just client. SHould not reside in /etc/init.d/ntp-client => belongs to /bin or /sbin

well but with these days software which do not keep the old structures properly, I may forgot to check for ntpd, or just overlooked it. 

The root cause can not be determined anymore ...

I will adapt my box and report back.

--

Thanks for the feedback

----------

## Jaglover

Everything is broken by design? DHCP client can be fine tuned to set only parameters you want. You can exclude DNS if you wish. Again, it is up to you to set it up properly. But first you should ask yourself whether you need DHCP or not. You may do better with static configuration.

----------

