# If using ntpd, do I also need ntp-client?

## Havin_it

Hi,

I did find one old thread about this, but it's from 2005 and I'm afraid the info might be out of date as the advice there didn't seem to match things on my system now.

I have two laptops and a server on my home network. Currently they all use ntp-client with NTPCLIENT_CMD="sntp" for setting their clocks. I thought I'd be a good netizen and set up ntpd on the server for the other machines to use rather than bothering public servers every boot.

What I'm not clear on is this: if ntpd is running on the server, should I still be running ntp-client (with NTPCLIENT_CMD="ntpd") on the same machine in order to update the clock? Or is ntpd doing this already?

Because it mentions it in /etc/conf.d/ntp-client, I tried configuring it to use NTPCLIENT_CMD="ntpd" but after various config attempts ntp-client won't start. That's mainly why I think I probably shouldn't be running both.

Can anyone clarify this? I was sure I remembered a good page in the Handbook that explained all this, but now I can't find it  :Sad: 

Thanks in advance.

----------

## Jaglover

AFAIK ntpd is client and server. BTW, there is lots more traffic than getting correct time at boot.

----------

## toralf

ntpd is slewing the clock if if the time difference is below a given limit. Any time differences greater that limit aren't handled by ntpd. IN such a case an explicitly time set is necessary (as done by ntp-client).

----------

## Havin_it

 *Jaglover wrote:*   

> AFAIK ntpd is client and server. BTW, there is lots more traffic than getting correct time at boot.

 

I think I see what you mean, having found a couple of other pages ( Wiki and Bug added a bit more to my understanding.

I have a couple of problems then. 

(A) ntpd is contacting the external servers so frequently that it outweighs the benefit of not having the two other machines do so every boot (even if this is at least a couple of times a day between them). Can I adjust the frequency of syncing to a much lower level to offset this?  It obviously needs doing occasionally for an always-on machine, but I'd imagine once a day or even less would be adequate.

(B) When the laptops go travelling, they can't use the local ntpd, so I have to leave at least one external server in the list for such occasions. But as far as I can tell, even when the IP of the local ntpd is available, sntp will still use the others as well, so nothing is gained! Two question here: Does sntp (or any of the other client options) *need* to use more than one server? And if not, can I somehow make it always try the local IP first, then fall back to the external ones? (That's how I thought it would work to start with.)

Also, after reading the argument in that bugreport, I'm not sure whether sntp is even working right now. There seems no definitive answer!

----------

## Jaglover

A - The interval will increase significantly once ntpd gets the clock under control and learns the drift.

B - I have no definite answer, I'm running ntpd in my router and all computers on my LAN use it as source.

----------

## Havin_it

Can't believe I spent most of yesterday messing about with this - NTP's documentation is very dense, not a fun read at all.

For the client machines, I decided to use NTPCLIENT_CMD="ntpd" as this seems to be the upstream-approved method now (and neither ntpdate or sntp seem to work properly at boot).  However, to achieve the host selection I seek I had to get a bit creative. I made a copy of ntp.conf called ntp-local.conf, where the local server replaces the pool.gentoo.ntp.org servers.  Then I made this script called "getntpconf":

```
#!/bin/sh

if ping -w1 <LOCALSERVER> &>/dev/null; then

        echo /etc/ntp-local.conf

else

        echo /etc/ntp.conf

fi
```

Then I change edit the NTPCLIENT_OPTS line in /etc/conf.d/ntp-client to

```
NTPCLIENT_OPTS="-g -q -c `/usr/local/bin/getntpconf`"
```

I always wondered if you could use backticked commands in conf.d files, and it appears you can, so problem solved  :Smile: 

What would be interesting would be to examine how much traffic ntpd generates. Is there any way I can monitor the program (or the port) to find this out?

----------

## Veldrin

 *Quote:*   

> What would be interesting would be to examine how much traffic ntpd generates. Is there any way I can monitor the program (or the port) to find this out?

 ntp uses port 123 (tcp and udp). you can use the usual suspects (tcpdump, wireshark) to analyse traffic.

IIRC the taffic is rather small.

cheers

V.

----------

## cwr

Below is the ntp.conf I use on my laptop - I check the time by hand, not automatically, on this

machine (using ntpd -q).  Then after rebooting with an ntpd server running it acts as a reference

source for the other machines on my intranet.

# NOTES:

#  - you should only have to update the server line below

#  - if you start getting lines like 'restrict' and 'fudge'

#    and you didnt add them, AND you run dhcpcd on your

#    network interfaces, be sure to add '-Y -N' to the

#    dhcpcd_ethX variables in /etc/conf.d/net

# Name of the servers ntpd should sync with

# Please respect the access policy as stated by the responsible person.

#server        ntp.example.tld        iburst

#server        ntplocal.example.com    prefer 

# Common pool for random people

#server pool.ntp.org

# Pools for UK users.

server 0.uk.pool.ntp.org

server 1.uk.pool.ntp.org

server 2.uk.pool.ntp.org

server 3.uk.pool.ntp.org

server uk.pool.ntp.org

##

# A list of available servers can be found here:

# http://www.pool.ntp.org/

# http://www.pool.ntp.org/#use

# A good way to get servers for your machine is:

# netselect -s 3 pool.ntp.org

##

# Internet time servers.

#server ntp2a.mcc.ac.uk

#server ntp2.strath.ac.uk

# Use this on local network devices other than the T23.

#server 193.237.32.199

# This says that the hardware clock is a (default level 5)

# reference. The pseudo-IP address is the index of a particular

# type of clock in the NTP source code. (See refclock.html)

#server 127.127.1.0 prefer

# Set clock-specific options.

#fudge 127.127.1.0 stratum 10

# You should not need to modify the following paths.

# (Drift checks the system clock against the reference clock.)

driftfile    /var/lib/ntp/ntp.drift

# Warning: Using default NTP settings will leave your NTP

# server accessible to all hosts on the Internet.

# If you want to deny all machines (including your own)

# from accessing the NTP server, uncomment:

#restrict default ignore

# To deny other machines from changing the

# configuration but allow localhost:

restrict default nomodify nopeer

restrict 127.0.0.1

# To allow machines within your network to synchronize

# their clocks with your server, but ensure they are

# not allowed to configure the server or used as peers

# to synchronize against, uncomment this line.

#

#restrict 192.168.0.0 mask 255.255.255.0 nomodify nopeer notrap

# Used by VirtualBox images.

#restrict 193.237.32.0 mask 255.255.255.192 nomodify nopeer notrap

# eof

----------

