I have a system of 3 or 4 different Linux Ubuntu machines that I would like to be time synced. My plan is to use one of them (let's call it master) as the NTP server that serves time to the 3 other machines (let's call them children).

However, I'd like to get UTC time first from the master and using online servers is not an option (no internet).

I'm currently reading UTC time from an on-board GPS device via C++. Is it possible to set the system time on this processor using C++ and the UTC time provided by a GPS and then use NTP to sync this time to all other children PCs?


A simple way is to use the date command

date -s @<seconds-since-1970>

If you want to do it in C++, see man settimeofday.

  • No, no, no. Don't ever try and set the time when you've got something like NTP running. Really. Here is why.
    – roaima
    Aug 14 '18 at 20:37
  • @roaima This is about setting the time on the master NTP server on a network without outside access. What do you recommend? And this is a correct answer to the question, even if you don't like the question, so why the downvote?
    – RalfFriedl
    Aug 14 '18 at 20:53
  • It's not a suitable solution when running NTPd. Read point #2 in the link I've provided in my first comment.
    – roaima
    Aug 15 '18 at 6:55
  • @roaima I thought it was about getting an initial time and then the NTP server provides this time to the clients. But your whole post in the link assumes that there is a time you can get from the network, and the question specifically states that there is no internet connection.
    – RalfFriedl
    Aug 15 '18 at 7:34

Yes, it is not only possible, but relatively straightforward. There are several "go-bys" and tutorials available ref 1, ref 2 that will show you how to do this.

A couple of other thoughts:

  1. consider using chronyd instead of ntpd. OpenNTPd would also be a good choice, except for the fact that it ignores leap seconds... but if you don't care about that, it's straightforward to use and administer.

  2. the accuracy of GPS time can vary a bit from one receiver to another.

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.