How to configure NTP over cross-over cable?

2

I'm fairly new to NTP. I have two computers running Lubuntu 17.04 that I'd like to keep in close time sync with minimal hardware. There is no need to sync to real time, just to keep the system times between the two computers as close as possible.

NTP seems to an appropriate solution. I succeeding in getting NTP working between the two computers, when configured with DHCP addresses (DHCP from a router, one PC is the NTP broadcast server and the other is the client, the PCs sync to each other and obtain close sync of ~1ms or less).

To reduce the amount of hardware I remove the router and set the IP's on each computer to static, then connect via a cross-over cable:

  • 10.1.1.50 255.255.255.0 (NTP "client" PC)
  • 10.1.1.51 255.255.255.0 (NTP "server" PC)

(Gateway was left blank in both cases.)

The PCs can ping each other successfully (delay is less than 1ms, around 0.3ms-0.4ms). However, I can't seem to get the ntp.conf configured; the NTP client computer just stays on INIT and all measures at 0. How can I debug the NTP configuration to find out where it is going wrong please?

There is no /var/lib/ntp/ntp.conf.dhcp file. Firewall is turned off for both PCs.

Output from ntpq -pn is

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.1.1.51       .INIT.          16 u    - 1024    0    0.000    0.000   0.000

Relevant lines from ntp.conf for the client are (i.e., all lines without comments)

driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 10.1.1.51
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict 10.1.1.0 mask 255.255.255.0
disable auth
broadcastclient

Relevant lines from ntp.conf for the server NTP PC are (i.e., all lines without comments)

driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 127.127.2.1 # local clock
fudge  127.127.2.1 stratum 10
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery
restrict 10.1.1.0 mask 255.255.255.0
broadcast 10.1.1.255

Using the command ntpdate -d 10.1.1.51 the problem seems to be that the NTP server 10.1.1.51 has too high a stratum level (as it is currently disconnected from the internet, and hence, it is not a trustworthy time source according to NTP).

Research suggests that it is not possible to fudge the stratum level of my isolated NTP server. Hence, I've enabled wifi on the NTP server and have attempted to allow it to sync to the standard Ubuntu pool of time servers, however ntpq -p takes a long time to respond with the cross over cable plugged in. I will check if my network config is correct and report back.

mark2017

Posted 2017-11-12T02:13:51.553

Reputation: 51

Is that 300ms accurate? It should be less than 1ms - did you mean 0.300ms - 0.400ms? If it is that high, then there is a networking problem. – Paul – 2017-11-12T02:42:01.440

My apologies, output of ping 10.1.1.51 from the client is 0.3 to 0.4 ms. (Question updated). – mark2017 – 2017-11-12T03:25:33.143

Answers

3

To use NTP via a cross-over cable, the NTP server PC has to be synchronising to other internet servers, otherwise its own stratum level drops too low and the client NTP PC rejects it as a valid server. In my case the solution was:

  1. Ensure cross over cable is set up correctly, both wired NICs should have no gateway and no DNS configured, and also be on a different subnet to the NTP server's wifi subnet. e.g. in my case, I moved the PC NICs to static IPs of

    • 10.1.2.50 255.255.255.0 (NTP "client" PC) No gateway, no DNS
    • 10.1.2.51 255.255.255.0 (NTP "server" PC) No gateway, no DNS

This is done in the Lubuntu "Edit Connections" GUI networking tool.

  1. Enable wifi on the NTP server PC, this allows it to get time synch from the internet. This is configured to the 10.1.1.n subnet, where n is allocated via DHCP from the wifi router. This has to be a different subnet from the wired NICs as discovered per https://askubuntu.com/questions/624830/ubuntu-using-wrong-nic-for-internet-connection

  2. Add the standard time servers that ship with the default ntp.conf file back in and ensure both ntp.conf files (client and server) are looking at the 10.1.2.0 subnet. Reboot everything and wait ten minutes for the NTP to start synchronising.

mark2017

Posted 2017-11-12T02:13:51.553

Reputation: 51

You can also configure the local clock as a master, es described here https://www.borngeek.com/2008/04/03/using-ntp-on-a-private-network/

– eckes – 2017-11-12T06:49:51.170

@eckes do you mean using # Use the local clock server 127.127.1.0 prefer fudge 127.127.1.0 stratum 10? I've found various references that indicate the fudge to the stratum of the local clock doesn't work, and it didn't in my experimentation. I found making the local clock a master doesn't help the synchronisation at all as the stratum level of the server still drops too low to be acceptable to the NTP client. – mark2017 – 2017-11-12T07:09:00.963

You should consider marking this as the accepted answer if it more closely represents how you solved the problem. – I say Reinstate Monica – 2017-11-13T13:06:15.343

@TwistyImpersonator thanks done as it exactly represents how the problem was solved. Also new to superuser still working out the kinks. Actually thought it was already marked as the answer as the superuser workflow indicated that I "answered" my own question, anyway, flagged now thanks for heads up. – mark2017 – 2017-11-14T20:29:13.873

BTW, I prefer corony, not only is the configuration cleaner it also has better centralized documentation. – eckes – 2017-11-15T06:25:02.663

1

This is what i could find for you:

http://www.brennan.id.au/09-Network_Time_Protocol.html

Stef

Posted 2017-11-12T02:13:51.553

Reputation: 67

1

Also check this for a relevant working tool - http://www.tldp.org/LDP/sag/html/ntp-toolkit.html

– Stef – 2017-11-12T04:11:41.977

thanks the tool ntpdate -d 10.1.1.51 indicates the problem is that the stratum level of the server is too high, most likely as it is isolated from the internet, so I need to check how I can have both the cross-over cable plugged in and wifi enabled on the NTP server. Internet will come down the wifi, and allow the NTP server to synchronise to higher stratum servers, but then I want to connect the NTP client via the cross over cable. So far, having both enabled at the same time doesn't seem to play nice together. – mark2017 – 2017-11-12T05:18:27.347

Indeed they deserve many thanks :) OK I solved it, I needed to configure the two NICs correctly, I will update the answer with details. – mark2017 – 2017-11-12T05:57:13.010

3Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change. – DavidPostill – 2017-11-12T08:32:27.413

@DavidPostill, actually I marked this as answer by accident. The relevant command from the ntp-toolkit (found at those links) to test the connection is ntpdate -d 10.1.1.51, it indicates the stratum of the NTP server here was too high (this is caused by it being disconnected from the internet, solution is the accepted answer). – mark2017 – 2017-11-14T20:36:15.200