Configure NTP Client Server: 5 Easy Steps and Mistakes
To configure NTP client server time sync, you need one server that answers on UDP port 123, a client that asks it, and a firewall that lets the packets through. The old version of this post was written for CentOS with the classic ntp package. This rewrite re-runs the idea on Debian 13 with ntpsec 1.2.3, in three containers on one network: a server (10.89.79.2), a client inside the allowed range (10.89.79.3) and a client outside it (10.89.79.200).
One limit: a container cannot set the host clock, so I proved the server and the access rules with ntpdig queries, and I did not get a running ntpd client to report synchronisation. The real ntpd client steps are therefore described, not shown with output.
Contents
- Step 1: install the software to configure NTP client server
- Step 2: configure NTP client server access with restrict
- Step 3: open UDP 123, not TCP, for the NTP client server link
- Step 4: check the NTP client server link with ntpdig
- Step 5: configure the NTP client to prefer your server
- Old commands that no longer work on an NTP client server
- Mistakes to avoid when you configure NTP client server
- Summary of how to configure NTP client server time sync
- FAQ
Step 1: install the software to configure NTP client server
On Debian 13 the package is ntpsec, with ntpsec-ntpdig for queries. The configuration file is /etc/ntpsec/ntp.conf, not /etc/ntp.conf:
$ dpkg -l ntpsec | tail -1 | awk '{print $2,$3}'
ntpsec 1.2.3+dfsg1-8
$ ls /etc/ntpsec/
ntp.conf
$ command -v ntpd ntpq ntpdig ntpstat ntpdate
/usr/sbin/ntpd
/usr/bin/ntpq
/usr/bin/ntpdig
Only ntpd, ntpq and ntpdig exist. The old post's check command ntpstat is not installed, and neither is ntpdate. Use ntpq -p and ntpdig instead. The NTPsec documentation covers the daemon and its options.
Step 2: configure NTP client server access with restrict
Access control is the part of a configure NTP client server job that people skip.
The old server configuration had four restrict lines that allowed two subnets with nomodify notrap, followed by a list of pool servers. It had no default restriction, which means any host that can reach the server gets time from it. A stricter file denies by default and then allows only your network:
restrict default nomodify notrap nopeer noquery noserve
restrict 127.0.0.1
restrict ::1
restrict 10.89.79.0 mask 255.255.255.128 nomodify notrap noquery
tos orphan 5 orphanwait 5
The network line allows clients in 10.89.79.0/25 (the .3 client but not the .200 one) to get time, and forbids them from changing the server (nomodify), from trap requests (notrap) and from status queries (noquery). For a real server, add the pool lines from the old post, for example server 0.pool.ntp.org iburst; see the NTP Pool instructions. My lab used tos orphan 5 instead, because the containers have no trusted upstream clock: with orphanwait 5, the server answered as stratum 5 after a few seconds:
$ ntpd -n -g -c /etc/ntpsec/ntp.conf -l /tmp/ntp.log &
$ ntpq -c rv
leap=00
stratum=5
refid=127.0.0.1
Do not use orphan mode as a replacement for real upstream servers in production.
Step 3: open UDP 123, not TCP, for the NTP client server link
The firewall is the other half of how you configure NTP client server traffic. The old post opened both TCP and UDP port 123 in iptables. NTP uses UDP only. The server's listening sockets show it:
$ ss -lun | grep 123
UNCONN 0 0 10.89.79.2:123 0.0.0.0:*
UNCONN 0 0 127.0.0.1:123 0.0.0.0:*
UNCONN 0 0 0.0.0.0:123 0.0.0.0:*
$ ss -ltn | grep 123
(no output: no TCP listener)
The firewall test used the old rule plus a UDP drop. A rule order mistake blocks the clients, and an accept rule placed first fixes it:
# iptables -A INPUT -p tcp -m state --state NEW --dport 123 -j ACCEPT
# iptables -A INPUT -p udp --dport 123 -j DROP
client$ ntpdig 10.89.79.2
ntpdig: no eligible servers
# iptables -I INPUT 1 -p udp --dport 123 -j ACCEPT
client$ ntpdig 10.89.79.2
2026-11-02 08:41:22.888303 (+0000) +0.000015 +/- 0.000071 10.89.79.2 s5 no-leap
The TCP rule from the old post had no effect on NTP. Rule order is the lesson: iptables stops at the first match, as shown in the iptables post.

Step 4: check the NTP client server link with ntpdig
$ ntpdig 10.89.79.2 # from 10.89.79.3, inside the range
2026-11-02 08:41:01.320088 (+0000) +0.000014 +/- 0.000077 10.89.79.2 s5 no-leap
$ ntpdig 10.89.79.2 # from 10.89.79.200, outside the range
ntpdig: no eligible servers
The first result is what a working NTP client server link looks like: it prints the server's time, the offset (+0.000014 seconds here, because all containers share the host clock), the error bound, the server and its stratum (s5). The outside client got no answer at all, which is what noserve does: the request is dropped without a reply. The noquery flag blocks status requests even for the allowed client:
$ ntpq -c "rv" 10.89.79.2
***Request timed out
Note that ntpdig -S asks to set the clock. In the container it printed CLOCK: step_systime: Operation not permitted before the answer; on a real host run it as root only when you want that step.
Step 5: configure the NTP client to prefer your server
The last piece when you configure NTP client server pairs is the client file itself.
The old client file listed the server with prefer and four pool servers. On a real client, the equivalent for ntpsec is:
server 10.89.79.2 prefer
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
Restart the daemon (the service name is no longer ntpd in this package; I only started the daemon by hand in the lab), then run ntpq -pn: a * in front of a peer means it is the selected source, and reach 377 means the last eight polls succeeded. I could not demonstrate this in a container, so check it on your own client and confirm that the client's firewall allows outgoing UDP 123 to the server, as the old post's OUTPUT rule did.
Old commands that no longer work on an NTP client server
$ ntpstat
bash: line 1: ntpstat: command not found
$ service ntpd start
ntpd: unrecognized service
$ netstat -tulpn
bash: line 1: netstat: command not found
Replace them with ntpq -p (or ntpq -c rv), the ntpsec service name, and ss -lun. I did not test CentOS, where the package and service names differ.
Mistakes to avoid when you configure NTP client server
- No default
restrictline, so any host can use the NTP client server you set up. - Opening TCP 123 and forgetting UDP 123.
- Putting a DROP rule for UDP 123 before the ACCEPT rule.
- Expecting
ntpstatorservice ntpdto exist on a modern Debian. - Using orphan mode as a time source on a production server.
Summary of how to configure NTP client server time sync
To configure NTP client server pairs that stay safe, deny by default with restrict default, allow only your own network, open UDP 123 in the right order, and verify with ntpdig from inside and outside the allowed range. Then add real upstream servers on the server and a prefer line on each client.
FAQ
How do I configure NTP client server time sync across subnets? Add one restrict line per client network on the server, and an outgoing UDP 123 rule on firewalled clients.
What is the simplest way to configure NTP client server sync for a small office? One server with the pool servers and a restrict line for the office subnet, and clients that list it first with prefer.
Why does ntpdig say "no eligible servers"? In this lab it meant no reply: the client was outside the allowed range, or a firewall dropped UDP 123.
Can I configure NTP client server sync inside a container? It can serve and query time, but it cannot set the clock, which belongs to the host.
Does a container keep its own clock? No. It shares the host clock, so time sync should run on the host, not inside the container.
Comments
Post a Comment