I have a project that wishes to force the times of a set of private NTP servers to demonstrate how NTP (and our software) reacts to various time changes and differences, network lag, etc.

Normally, we'd set up a virtual network of VMs to demonstrate our software, but I can't seem to find one that will allow NTP to run independently in each VM. For this we'd need a software clock.

So far, I've looked at:

  • Docker - ties their clock to the hardware clock of the host, privileges are one issue, but the main issue is that if the clock is changed all clocks running in all VMs on that host are changed.

  • VirtualBox - This answer suggests that even with guest-additions, the lack of a high-resolution clock would make this impossible.

Is there any software that can virtualize a hardware clock for NTP, or otherwise run independent clocks on the same machine at the same time?

  • 1
    Setup a VM that runs a NTP server but not connected to any NTP source the setup another VM that trusts that VM has its only NTP source – Ramhound Mar 1 '16 at 2:36
  • @Ramhound - in which environment? – tu-Reinstate Monica-dor duh Mar 1 '16 at 2:50
  • That's entirely Up to you – Ramhound Mar 1 '16 at 3:03
  • 2
    @Ramhound - That's actually the main part of the question. Docker ties the clock to the hardware. VirtualBox won't work because of a high-resolution clock. See the question. – tu-Reinstate Monica-dor duh Mar 1 '16 at 3:12

It is not clear if you are interested in

  • how ntp behaves under some set of circumstances.

  • how your software behaves due to time changes and you have decided the best way to introduce these time changes is fiddling with ntp.

If you are simply interested in the former check out ntpdsim. It is part of the ntp reference implementation:

The ntpdsim program is used to simulate and study the behavior of an NTP daemon that derives its time from a number of different simulated time sources (servers). Each simulated server can be configured to have a different time offset, frequency offset, propagation delay, processing delay, network jitter and oscillator wander.

If you are interested in the later, use ntpdsim to see how your ntp servers will react to the changes. Then take this information and use a cronjob or something similar to modify the clocks on your vms according to the information you learned from the ntpdsim runs...


| improve this answer | |
  • My apologies that I didn't see this answer earlier. That's an excellent solution! I'm actually interested in both. We had some failures with clocks and were suddenly required to prove that our software handled the situation correctly where two or more NTP servers disagreed. As a corollary, they insisted that they be able to manually manipulate the clocks in the virtual machines both independently (to simulate failures) and together (to assess things like daylight savings time), obviously this meant that the hardware clocks had to remain intact throughout all simulated time changes. – tu-Reinstate Monica-dor duh Feb 10 '17 at 7:03

Red Hat's documentation suggests that at least one of the libvirt hypervisors support configurable clock sources (or at least custom offsets): https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/sect-Virtualization-Tips_and_tricks-Libvirt_Managed_Timers.html

KVM is one of the libvirt hypervisors, and at least one person describes accidental desynchronisation: https://unix.stackexchange.com/q/83934/63149

(Apologies for formatting -- I'm on mobile and originally intended to just drop this as a comment!)

| improve this answer | |

As RJHunter stated, it is entirely possible to get NTP working on multiple KVM instances, however it will probably not be extremely accurate.

This link goes into details about KVM.

| 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.