# ntp setup guide?

## pgu

I'm looking for a ntp guide on how to set up one server on your network and sync the clocks on all the machines on the local network to it, then make the server sync itself to a public ntp server on the net. High  precision wall time is not that important, but I would like all the machines on the net to be in sync.

----------

## palmer

It's not really a guide, but I have exactly that setup.

I installed NTP via portage, it's the same on the client (desktop) and server (server)

```
server ~ # emerge -vp ntp

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R    ] net-misc/ntp-4.2.6_p3  USE="ipv6 ssl -caps -debug -openntpd -parse-clocks (-selinux) -snmp -vim-syntax -zeroconf" 4,217 kB

Total: 1 package (1 reinstall), Size of downloads: 4,217 kB
```

```
desktop ~ # emerge -vp ntp

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R    ] net-misc/ntp-4.2.6_p3  USE="ipv6 ssl -caps -debug -openntpd -parse-clocks (-selinux) -snmp -vim-syntax -zeroconf" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB
```

The only config file you need is "/etc/ntp.conf".  It's different on the server (set to sync with us.pool.ntp.org) and the clients (set to sync with the server).  On the clients you can replace "server.dabbelt.com" with the hostname or IP of your NTP server.

```
server ~ # cat /etc/ntp.conf 

server 0.us.pool.ntp.org

server 1.us.pool.ntp.org

server 2.us.pool.ntp.org

server 3.us.pool.ntp.org

driftfile   /var/lib/ntp/ntp.drift

restrict default nomodify nopeer

restrict 127.0.0.1
```

```
desktop ~ # cat /etc/ntp.conf 

server server.dabbelt.com

driftfile   /var/lib/ntp/ntp.drift

restrict default nomodify nopeer

restrict 127.0.0.1
```

If you then start ntp on both boxes (via "/etc/init.d/ntp start") and wait a while (maybe an hour or so, ntp can take a while to start syncing) you'll see it synchronized (the IP of "server.dabbelt.com" is "10.1.1.1").

```
server ~ # ntpq -pn

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

+208.53.158.34   204.9.54.119     2 u  527 1024  377   35.722   -2.399   2.118

+208.85.173.56   138.39.23.13     2 u  683 1024  377   23.051    0.017   2.194

-184.105.182.7   209.81.9.7       2 u  485 1024  377   96.765   -8.405   1.965

*50.19.122.125   209.51.161.238   2 u  935 1024  377   20.700   -0.483   2.352
```

```
desktop ~ # ntpq -pn

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

*10.1.1.1        50.19.122.125    3 u  893 1024  377    0.224    1.047   0.746
```

I've found that it's convenient to start "/etc/init.d/ntpdate" at the default runlevel to sync with the global NTP servers to get you time close to the correct time, as this makes NTP start to sync faster.  You'll probably want to "/etc/init.d/ntpdate start" before starting ntp for the first time on both the client and the server for the same reason.  You'll of course also want to add "/etc/init.d/ntp" to default to get the NTP servers to start syncing when you reboot.

I've found it's best to not do anything that changes the system time (ie run "date" or "ntpdate" or "/etc/init.d/ntpdate") while the NTP daemon is running (there shouldn't be any reason to, as your time should stay in sync perfectly).Last edited by palmer on Sun Mar 18, 2012 8:33 pm; edited 1 time in total

----------

## Ant P.

http://www.gentoo.org/doc/en/home-router-howto.xml

----------

## pgu

Thank you for the guide.

The problem is that on the client side ntpd will start, and run, but after some time it will die without leaving any traces in the logfiles  :Sad: 

----------

## gentoo_ram

There is a sanity check when NTP starts to make sure it doesn't change the clock by too much.  Manually set the clock to close to the correct time before starting NTP.

----------

## Veldrin

 *gentoo_ram wrote:*   

> There is a sanity check when NTP starts to make sure it doesn't change the clock by too much.  Manually set the clock to close to the correct time before starting NTP.

 

or just add -g (--panicgate) to NTPD_OPTS in /etc/conf.d/ntpd, which allow a large clock change at start time.

V.

----------

## pgu

Thanks! That was the reason.Now that I used ntpdate first to get a more correct clock before I started ntpd it actually worked.

----------

