20

there are so many tutorials out there explaining how to setup dhcpd server, in relation to providing ntp suggestions to dhcp clients, that I had always thought that ntp configuration was carried out automatically. Recently I started seeing clock drifts in my local network, so I assume this was a wrong assumption. So I set out to see how can one minimize the ntp client configuration, provided one has carried out the effort to set up ntp-server suggestions through dhcpd.

I have not been able to find much apart from this Ubuntu specific help tutorial https://help.ubuntu.com/community/UbuntuTime . Even here (see paragraph under "Troubleshooting -> Which configuration file is it using?") the information is scarce but it says that if an /etc/ntp.conf.dhcp file is found it will be used instead. First of all the actual location that the writer meant here is /var/lib/ntp/ntp.conf.dhcp as observed in /etc/init.d/ntp , but regardless of that the presence of this file does not guarantee that the ntp will request servers from dhclient. As a result, I have to explicitly add the server clause in ntp.conf.dhcp for my local ntp server. But in that case, why do I even setup ntp settings on the dhcpd server?

This seems to go against intuition, ie setup ntp settings once (ie on the server) and let dhcpd server delegate the information to the clients. How can I minimize (if not avoid altogether), client configuration for the ntp. Alternatively, how can I get ntp information through dhclient.

Is there a cli solution that fits all linux distros?

I assume every client should have the executables of ntpd, but I do not know how to proceed from there.

Thank you

EDIT: ubuntu client verbose output when running manually dhclient:

sudo dhclient -1 -d -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0
Internet Systems Consortium DHCP Client 4.2.4
Copyright 2004-2012 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth0/20:cf:30:0e:6c:12
Sending on   LPF/eth0/20:cf:30:0e:6c:12
Sending on   Socket/fallback
DHCPREQUEST of 192.168.112.150 on eth0 to 255.255.255.255 port 67 (xid=0x2e844b8f)
DHCPACK of 192.168.112.150 from 192.168.112.112
reload: Unknown instance: 
invoke-rc.d: initscript smbd, action "reload" failed.
RTNETLINK answers: File exists
 * Stopping NTP server ntpd
   ...done.
 * Starting NTP server ntpd
   ...done.
bound to 192.168.112.150 -- renewal in 41963 seconds.

The ntpd service is restarted, yet running ntpq -cpe -cas afterwards I still do not see my local ntp server in the list of ntp servers.

Of course my dhcpd server does have option ntp-servers

subnet 192.168.112.0 netmask 255.255.255.0 {
        max-lease-time 604800;
        default-lease-time 86400;
        authoritative;
        ignore client-updates;

        option ntp-servers 192.168.112.112; #self

        ... (many other options)
}
  • 1
    In my DHCPD server I pass to the clients the NTP server to use with option ntp-servers x.x.x.x – Rui F Ribeiro Dec 4 '16 at 15:27
  • @RuiFRibeiro Hi there, yes this option is indeed part of my dhcpd server. – nass Dec 4 '16 at 15:51
  • 2
    serverfault.com/questions/329596/… may give you some clues. You probably want to look at /etc/dhcp/dhclient-exit-hooks.d/ntp to find the actual filename being used. Make sure that your dhclient.conf file is set up to request ntp-servers as well. – icarus Dec 4 '16 at 17:49
  • You're using Ubuntu as to client? Which version? – roaima Mar 6 '17 at 8:57
  • @roaima client may be ubuntu but a more generic solution would help. If it make things any easier, lets say ubuntu 14.04 LTS is the client in this case. – nass Mar 6 '17 at 9:22
13
+50

If the dhcp server you are using is configured to provide the ntp-servers option, you can configure your dhclient to request ntp-servers by adding ntp-servers to the default request line in dhclient.conf, as shown at the end of this example from Ubuntu Linux (as of 19.04, but present since at least 12.04):

request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;

/etc/ntp.conf and the information from DHCP will be used to create /etc/ntp.conf.dhcp.

Your ntpd must be told to use /etc/ntp.conf.dhcp if it exists. On the version of Ubuntu that I'm using, this is done via /etc/dhcp/dhclient-exit-hooks.d/ntp. <-- this is the file that tells NTPd to use /etc/ntp.conf.dhcp if it exists, and to just use /etc/ntp.conf if it doesn't.

| improve this answer | |
  • 2
    In Ubuntu 18.04 this file is in /run/ntp.conf.dhcp, you can look up it's location in any event in /etc/dhcp/dhclient-exit-hooks.d/ntp – DustWolf Aug 9 '18 at 13:59
  • It appears that the latest Ubuntu 16.04 xenial no longer support ntp-options; it used to work fine. Doing this: /usr/sbin/dhcpd -t gives this: /etc/dhcp/dhcpd.conf line 20: unknown option dhcp.ntp-server option ntp-server 10. ... it was working fine back in the summer. – Linas Nov 5 '19 at 3:18
0

chronyd being used these dayd, yes it still use NTP protocol. You might went to check couple of sources:

https://docs.oracle.com/cd/E52668_01/E54669/html/section_zy2_rrf_pp.html

https://wiki.archlinux.org/index.php/Chrony

http://chrony.tuxfamily.org/faq.html#_i_have_several_computers_on_a_lan_should_be_all_clients_of_an_external_server

https://docs.fedoraproject.org/en-US/Fedora/18/html/System_Administrators_Guide/chap-Configuring_NTP_Using_the_chrony_Suite.html

I recommend the last 2.

| improve this answer | |
  • 1
    Hi Abdullah, Chrony is a useful alternative to be aware of but your answer doesn't show how it can be used to get DHCP clients to make use of the NTP information provided by a DHCP server. – Anthony Geoghegan Mar 6 '17 at 11:24
  • @AnthonyGeoghegan Hello, If you add it as a comment I would delete my answer, – Abdullah Mar 6 '17 at 11:33
  • 2
    Don't just post some links (these tend to rot away) but include the needed information in your answer. – Martin Schröder Aug 15 '18 at 21:05
0

It really depends on the network-setup/dhcp/NTP components you are using and for which combination your distribution did integration work.

As of 2020, at least some distributions consider Chrony as the better1 alternative to NTPD and thus Chrony is installed by default and the integration of a DHCP client with a DHCP client is only maintained for Chrony then.

For network setup a popular default among distributions is NetworkManager (whereas NetworkManager deals with automatically calling the DHCP client with the distributions default configuration). Thus, the expectation is that the DHCP supplied (local) NTP server is selected if you use your distributions defaults, meaning NetworkManager and Chrony.

NetworkManager and Chrony

When using Chrony you can verify if your DHCP announced NTP server was communicated to Chrony like this:

# chronyc sources
210 Number of sources = 5
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^- fritz.box                     3   6     0  1015   +627us[  -23us] +/-   47ms
^* ntp3.rrze.ipv6.uni-erlan>     1   7   377    47   +997us[+1007us] +/-   26ms
^+ tethys.hot-chilli.net         2   7   377    47   +522us[ +533us] +/-   51ms
^+ mail.jabber-germany.de        3   7   377    46   +352us[ +352us] +/-   61ms
^+ 2a.ncomputers.org             2   7   377    44  -2900us[-2900us] +/-   73ms

(This is from a Fedora 31 system with NetworkManager and Chrony using the default configuration.)

The example shows that my local NTP server included in my home router (fritz.box) which is announced via DHCP is actually made known to Chrony (by some NetworkManager glue config/code), but currently it isn't used by Chrony (cf. M -> - -i.e. the second column) because the last 8 replies weren't valid (cf. Reach -> 0).

S
    This column indicates the state of the source.
      ·   * indicates the source to which chronyd is currently
            synchronised.
      ·   + indicates acceptable sources which are combined with the
            selected source.
      ·   - indicates acceptable sources which are excluded by the
            combining algorithm.

[..] Reach This shows the source’s reachability register printed as an octal number. The register has 8 bits and is updated on every received or missed packet from the source. A value of 377 indicates that a valid reply was received for all from the last eight transmissions.

(chronyc(1) on F32)

As you see, with such distributions everything should work out of the box.2 You just have to make sure that Chrony and NetworkManager is installed (and that your local NTP server sends valid replies).

Networkd and Timesyncd

Networkd and Timesyncd are ports of systemd and when enabled (instead of NetworkdManager and Chrony) they deal with the network setup and as NTP client.

If systemd is already in use (it likely is) it can be considered as more lightweight alternative to NetworkManager and Chrony for servers and small embedded devices. However, some distributions like RHEL/CentOS 8 don't package those components.

When both Networkd and Timesyncd are enabled, Networkd by default makes the DHCP supplied NTP server available to Timesyncd which prefers it over others.


1 See also:

Chrony should be preferred for all systems except for the systems that are managed or monitored by tools that do not support chrony, or the systems that have a hardware reference clock which cannot be used with chrony.

(RedHat's recommendation in its RHEL 7 admin guide)

From a security standpoint (and here at the CII we are security people), Chrony was the clear winner between these three NTP implementations.

(From a Core Infrastructure Initiative commissioned security 2017 audit, via LWN)

Chrony's comparison of NTP implemenations

2 Modulo bugs, of course. For example past bugs in Fedora:

| improve this answer | |

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.