2

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?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Frank
  • 121

2 Answers2

2

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.

RalfFriedl
  • 8,981
  • No, no, no. Don't ever try and set the time when you've got something like NTP running. Really. Here is why. – Chris Davies 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. – Chris Davies Aug 15 '18 at 06: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 07:34
1

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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Seamus
  • 2,925