# NTP incorrect date and time

## MattMurdock

I'm running KDE and have it configured to set the time and date automatically through NTP. Unfortunately the date and time are wrong by almost a day, and as of yet I haven't been able to diagnose the cause. Any help would be great.

Here's some info on my system and what I've tried so far:

Set timezone to Auckland/New Zealand during installation with

```
# cp /usr/share/zoneinfo/Pacific/Auckland /etc/localtime

# cat /etc/timezone 

Pacific/Auckland
```

Contents of /etc/conf.d/hwclock (default):

```
clock="UTC"

clock_systohc="NO"

clock_hctosys="YES"

clock_args=""
```

/etc/ntp.conf is default, i.e. the ntp servers are

```
server 0.gentoo.pool.ntp.org
```

etc.

As of writing the time is 3:30 PM Sun 15th Jan 2012, this is what ntpdate returns:

```
# ntptime

ntp_gettime() returns code 5 (ERROR)

  time d2bd6b2f.b11ec000  Mon, Jan 16 2012  4:11:43.691, (.691875),

  maximum error 16000000 us, estimated error 16000000 us, TAI offset 0

ntp_adjtime() returns code 5 (ERROR)

  modes 0x0 (),

  offset 0.000 us, frequency 0.000 ppm, interval 1 s,

  maximum error 16000000 us, estimated error 16000000 us,

  status 0x40 (UNSYNC),

  time constant 2, precision 1.000 us, tolerance 500 ppm,
```

Messages from ntp daemon in /var/log/syslog:

```
...

Jan 16 04:12:16 matt-gentoo-desktop /etc/init.d/net.eth0[3726]: ERROR: net.eth0 failed to start 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3818]: ntpd 4.2.6p3@1.2290-o Tue Dec 27 18:19:24 UTC 2011 (1) 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: proto: precision = 0.130 usec 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: Listen and drop on 1 v6wildcard :: UDP 123 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: Listen normally on 2 lo 127.0.0.1 UDP 123 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: Listen normally on 3 eth0 10.1.1.2 UDP 123 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: Listen normally on 4 eth0 xxxx::xxxx:xxx:xxxx:xxxx UDP 123 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: Listen normally on 5 lo ::1 UDP 123 

Jan 16 04:12:17 matt-gentoo-desktop ntpd[3819]: peers refreshed 

Jan 16 04:16:09 matt-gentoo-desktop dhcpcd[3367]: eth0: renewing lease of 10.1.1.2 

Jan 16 04:16:09 matt-gentoo-desktop dhcpcd[3367]: eth0: acknowledged 10.1.1.2 from 10.1.1.1 

Jan 16 04:16:09 matt-gentoo-desktop dhcpcd[3367]: eth0: leased 10.1.1.2 for 3600 seconds 

...
```

Cheers

----------

## salahx

It might not set the date and time if the clock is too far off (more than 1000 seconds), try using "ntpd -g -q"

----------

## MattMurdock

Ok I tried "ntpd -g -q" after which ntptime is returning the correct date/time. However after a computer restart ntptime was returning Mon Jan 16th (incorrect) again.

So in /etc/conf.d/hwclock I changed:

```
clock_systohc="NO"

clock_hctosys="YES"
```

to

```
clock_systohc="YES"

clock_hctosys="NO"
```

and after a restart both ntptime and KDE are reporting the correct time. So far so good  :Smile: 

However ntptime is still giving 

```
ntp_gettime() returns code 5 (ERROR)
```

which apparently is a "clock not synchronised" error. It also states "estimated error 16000000 us". What's going on here?

----------

## PaulBredbury

For debugging, see wiki entry.

----------

