17

I'm running Ubuntu in a VM. How do I disable ntpd?

3
  • 1
    Out of curiosity, why would you want to? Does it do harm when running on a VM?
    – Snekse
    Dec 19, 2012 at 19:04
  • 1
    Use case: To test what happens to an embedded system if ntp is not available. May 24, 2017 at 12:45
  • Did you ever figure out what happens if NTP is not available ? I have an embedded system and currently trying to figure out the same thing.
    – VanGo
    Mar 25, 2020 at 0:20

3 Answers 3

18

To stop ntpd:

sudo /etc/init.d/ntp stop

or

sudo service ntp stop

To prevent it from starting at boot:

sudo update-rc.d -f ntp remove
2
  • None of these work for me on Ubuntu 18.04. Jan 10, 2019 at 4:37
  • @AaronFranke This answer was posted in 2011! For an up-to-date version (working in 18.04) please see @knb answer. Jan 10, 2019 at 9:47
8

With systemd, the two commands are:

sudo systemctl stop ntp
sudo systemctl disable ntp

Output (I think the warning can be ignored)

ntp.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install disable ntp
insserv: warning: current start runlevel(s) (empty) of script `ntp' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (1 2 3 4 5) of script `ntp' overrides LSB defaults (1).
insserv: warning: current start runlevel(s) (empty) of script `ntp' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (1 2 3 4 5) of script `ntp' overrides LSB defaults (1).

Check:

systemctl is-enabled ntp

Output

ntp.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install is-enabled ntp
disabled
2
  • 1
    Under Ubuntu 18.04 and later, the systemd service name is systemd-timesyncd.service Jul 2, 2019 at 0:35
  • I think that if you have upgraded from 16.04 to 18.04, it is still called ntp.
    – knb
    Jul 2, 2019 at 7:30
5

Uninstall ntpd if it is installed. You will still have ntpdate installed. (It is difficult to remove.) Prevent it from executing by adding exit 0 to /etc/default/ntpdate.

Update: This is an old answer. Most systems now use systemctl to run commands. To disable ntp and ntpdate issue the commands:

systemctl disable ntp.service 
systemctl disable ntpdate.service 

You can check the status of ntp related units with the command:

 systemctl list-unit-files | grep ntp    
2
  • Are you sure about this? /etc/default/ntpdate is just a configuration file. Dunno if it is sourced by any bash script, but I guess it's useless to add exit.
    – Gelma
    Mar 4, 2021 at 10:02
  • @Gelma files in /etc/default are usually sourced by the script running the related command. This was always the case for commands run by init.d scripts. Commands run by systemctl may not source the file. See update for the systemctl option.
    – BillThor
    Mar 9, 2021 at 17:50

You must log in to answer this question.