9

I have a server in a network receiving all its network information from DHCP. The problem is that the ntp-server being sent is not set to UTC. I want to use the configuration for ntp found in /etc/ntp.conf but the DHCP information takes precedence. How can I force ntpd to use the configuration in /etc/ntp.conf as opposed to the one sent by DHCP? What is the Debian way to do this?

3
  • What ntp daemon are you using? What is the current contents of your ntp.conf? Is the ntpdate package installed? What DHCP client are you using? What version of Debian?
    – Zoredache
    Nov 10, 2011 at 4:09
  • 1
    1. Sever on DHCP 2. NTP server is not "set" to UTC o_O
    – Chris S
    Nov 10, 2011 at 4:57
  • Debian squeeze, default ntp.conf (the one that comes after aptitude install ntp) Nov 10, 2011 at 20:35

3 Answers 3

8

I suggest you edit/create /etc/dhclient.conf and uncomment the line "request" with something like this:

request subnet-mask, broadcast-address, routers, domain-name, domain-name-servers, host-name;

Especially, if "ntp-servers" is present, remove it. Under some distribution ( aka Fedora ) it is sent by default, so you have to put this line explicitely so that the default is overriden.

Check man dhclient.conf for extended informations.

2
  • This worked perfectly... is there something that one can do in debian that goes more along the lines of /etc/default... Nov 10, 2011 at 20:34
  • Regrettably this doesn't seem to work on Ubuntu 16.04 LTS. dhclient creates its override configuration even though ntp-servers is removed from the request line in /etc/dhclient.conf. May 18, 2020 at 16:33
17

Not directly answering the question but that may come in handy.

DHCP behavior

On Debian (at least) the DHCP client is overriding the existing ntp service configuration.

It is controlled by the script /etc/dhcp/dhclient-exit-hooks.d/ntp:

[contents from: /etc/dhcp/dhclient-exit-hooks.d/ntp]
NTP_CONF=/etc/ntp.conf
NTP_DHCP_CONF=/var/lib/ntp/ntp.conf.dhcp
...
[hundreds of lines of scripts]

The DHCP client receive ntp servers from the DHCP server, it grabs the current ntp service configuration from NTP_CONF path and alters it to include ntp servers received over dhcp, it generates a new ntp configuration file into NTP_DHCP_CONF path, and finally it forces the ntp service to use this new configuration file.

This results in always using the ntp servers advertised over dhcp. Bypassing system configuration.

This is hard to debug if not known because the service configuration in '/etc/ntp.conf' is left untouched and is correct on visual inspection. However it is actually ignored and overridden stealthy.

You can use 'ntpq -pn' to debug what ntp servers are actually being used by the deamon.

Mixing DHCP ntp options and system specific configuration

If there IS a ntp server in your network being advertised by DHCP and you want to ignore it:

You will need to reconfigure the dhcp client in /etc/dhclient.conf to skip the ntp-servers dhcp option. Refer to the answer from @Oliver.

Then you can customize the system configuration in /etc/ntp.conf

If there WAS a ntp server advertised by DHCP at some point but not anymore:

The system ntp configuration might still be overridden by the dhcp client, forcing obsolete ntp servers advertised a long time ago. This dhcp overriding can survive for days, across ntp service restart and reboot.

To put an end to it, you will need to remove /var/lib/ntp/ntp.conf.dhcp and restart the ntp service on all your servers.

Final Word

This is all undocumented, unexpected and hard to debug behavior. That caused me quite the headache today which is why I am documenting this in here.

1
  • For the records, that file /etc/dhcp/dhclient-exit-hooks.d/ntp is part of the ntp package. So it is the ntp package that tweaks the dhcp client into overriding its own (ntp's) config if an ntp server is provided via dhcp. Then the startscript /etc/init.d/ntp has some magic to pick up the config from /run/ntp.conf.dhcp Jan 10, 2023 at 15:00
7

You can also just remove this file: /etc/dhcp/dhclient-exit-hooks.d/ntp, instead of editing your DHCP-requests. This file creates ntp.conf.dhcp.

In case ntp.conf.dhcp got created at a previous boot, be sure to remove it as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .