How to configure a custom NTP server?

Problem

You cannot configure custom NTP server(s), NTP continues to use metadata.google.internal as default.

Environment

  • Linux
  • Chrony
  • dhclient
  • NTP

Solution

  1. Rename or move out the chrony or chrony.sh script.
  2. Remove the contents of the file chrony.servers.*.
  3. Edit chrony.conf, commenting out/removing metadata server and adding your custom NTP server(s).
  4. Restart instance or restart chronyd service using the following command:
    $ sudo systemctl restart chrony

File locations on respective Operating systems:

  • Red Hat:
    • /etc/dhcp/dhclient.d/chrony.sh
    • /var/lib/dhclient/chrony.servers.*
    • /etc/chrony.conf
  • Debian:
    • /etc/dhcp/dhclient-exit-hooks.d/chrony
    • /var/lib/dhcp/chrony.servers.*
    • /etc/chrony/chrony.conf
  • Ubuntu:
    • /etc/chrony/chrony.conf
    • /etc/dhcp/dhclient-exit-hooks.d/chrony
    • /var/lib/dhcp/chrony.servers.*

Cause

Solving this will require manipulation of specific configuration files and/or scripts. The location and naming for those might vary slightly, depending on the Linux Distribution you are using. The file locations and names respective to Red Hat, Debian and Ubuntu Distributions have been added below, for your convenience.