0

I use Ubuntu server 16.04 and I set up local NTP server with the following configs in /etc/ntp.conf file:

# this is the IP or name of the local networks NTP ser$
# should be commented out on the server
# server 192.168.1.202 iburst         # this line is uncommented for clients

# this enables checking the local clock. Do not change$
server 127.127.1.0
fudge 127.127.1.0 stratum 10

# this lines are required to run the ntpq -p command t$
# function of the system

restrict 127.0.0.1
restrict ::1

The problem is when I restart the system, time is not synced and correct and even is wrong! Output of the command timedate status in server:

Local time: Thu 2018-02-22 19:03:50 IRST
  Universal time: Thu 2018-02-22 15:33:50 UTC
        RTC time: Thu 2018-02-22 15:33:50
       Time zone: Asia/Tehran (IRST, +0330)
 Network time on: no
NTP synchronized: yes
 RTC in local TZ: no

Here UTC time is the correct local time. in the clients:

Local time: Mon 2018-02-19 02:07:18 IRST
  Universal time: Sun 2018-02-18 22:37:18 UTC
        RTC time: Sun 2018-02-18 22:37:19
       Time zone: Asia/Tehran (IRST, +0330)
 Network time on: no
NTP synchronized: yes
 RTC in local TZ: no

In server machine the date is correct but the time is wrong. In client machine both are wrong. The peers in clients are ntpq -p:

    remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.1.202    LOCAL(0)        11 u   46   64    1    0.381  3201920   0.011
*LOCAL(0)        .LOCL.          10 l   17   64  377    0.000    0.000   0.000

But when I use command sudo apt update date became correct in clients:

    Local time: Thu 2018-02-22 19:16:44 IRST
  Universal time: Thu 2018-02-22 15:46:44 UTC
        RTC time: Sun 2018-02-18 22:50:13
       Time zone: Asia/Tehran (IRST, +0330)
 Network time on: no
NTP synchronized: no
 RTC in local TZ: no

But time still is wrong! I used the command date -s "correct time and date", but after restarting it goes wrong!

How can I fix the problem!

  • Can you include the output of ntpq -p and echo rv | ntpq on the server in your question? – vidarlo Feb 22 '18 at 12:27
  • @vidarlo The post contains ntpq -p – Soheil Pourbafrani Feb 22 '18 at 12:42
  • have you tried timedatectl set-ntp 1 ? Also, it takes a few minutes until your machine is synchronized with the NTP server. – Abel Tom Feb 22 '18 at 12:50
  • Yes, but it is not permanently. I want everything works correctly after rebooting, but everything becomes messy! – Soheil Pourbafrani Feb 22 '18 at 12:58
  • I was thinking of ntpq -p on the server, not the client. But it's not needed; see my answer. – vidarlo Feb 22 '18 at 13:05
0
    remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.1.202    LOCAL(0)        11 u   46   64    1    0.381  3201920   0.011
*LOCAL(0)        .LOCL.          10 l   17   64  377    0.000    0.000   0.000

This is the output of ntpq -p on the client, and it is essentially the answer to why the client does not sync. The client uses it's own clock as a stratum 10 reference - but the server claims it is stratum 11.

NTP treats lower stratum clocks as more likely to be correct. Here you have two time sources, one with stratum 11 and one with 10 - and a huge difference. It won't attempt to reconcile them - it will simply say that the stratum 11 one is wrong.

Set the server to a lower stratum, using the

fudge 127.127.1.0 stratum 9

for instance. Or - preferably sync the server to an external time source that is more reliable, for instance one of the NTP pools, which is generally stratum 1-3. Syncing to a stratum 3 NTP server would make your NTP server a stratum 4 NTP server, which would be preferred over the local clock.

Another alternative is to increase the stratum of your local clock on the clients, for instance to 13.

  • Thanks, Can you say why the time and date is wrong at the startup. I set them using the command sudo date -s "MYTIME" but after restarting it bach to the wrong time and date!!! – Soheil Pourbafrani Feb 22 '18 at 13:09
  • 1
    wiki.debian.org/DateTime explains why. – vidarlo Feb 22 '18 at 13:13
  • I mean How can I set correct time, permanently – Soheil Pourbafrani Feb 22 '18 at 13:24
  • sudo hwclock -w will write it to the systems hardware clock. But it will hardly be permanent; clocks drift. That is why we have NTP. In addition, Ubuntu should write hwclock on shutdown... – vidarlo Feb 22 '18 at 13:25
  • 1
    hwclock -w writes system time to hardware clock. – vidarlo Feb 22 '18 at 13:35

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.