How to bind ntpd to specific IP addresses on Linux/Unix

last updated in Categories , ,

By default, my ntpd/NTP server listens on all interfaces or IP address i.e How do I make sure ntpd only listen on a specific IP address such as localhost or on a Linux or FreeBSD Unix server?

NTP is an acronym for Network Time Protocol. It is used for clock synchronization between computers. The ntpd program is an operating system daemon which sets and maintains the system time of day in synchronism with Internet standard time servers.
How to prevent NTPD from listening on and binding to specific IP addresses on a Linux/Unix server
The NTP is configured using ntp.conf located in /etc/ directory.


interface directive in /etc/ntp.conf

You can prevent ntpd to listen on by setting the interface command. The syntax is:
interface listen IPv4|IPv6|all
interface ignore IPv4|IPv6|all
interface drop IPv4|IPv6|all

The above configures which network addresses ntpd listens or dropped without processing any requests. The ignore prevents opening matching addresses, drop causes ntpd to open the address and drop all received packets without examination. For example to ignore listing on all interfaces, add the following in /etc/ntp.conf:
interface ignore wildcard
To listen to only and addresses:
interface listen
interface listen

Here is my sample /etc/ntp.conf file from FreeBSD cloud server:
$ egrep -v '^#|$^' /etc/ntp.conf
Sample outputs:

tos minclock 3 maxclock 6
pool iburst
restrict    default limited kod nomodify notrap noquery nopeer
restrict -6 default limited kod nomodify notrap noquery nopeer
restrict    source  limited kod nomodify notrap noquery
restrict -6 ::1
leapfile "/var/db/ntpd.leap-seconds.list"
interface ignore wildcard
interface listen
interface listen

Restart ntpd

Reload/restart the ntpd on a FreeBSD unix:
$ sudo /etc/rc.d/ntpd restart
OR use the following command on a Debian/Ubuntu Linux:
$ sudo systemctl restart ntp
OR use the following on a CentOS/RHEL 7/Fedora Linux:
$ sudo systemctl restart ntpd


Use the netstat command/ss command for verification or to make sure ntpd bind to the specific IP address only:
$ netstat -tulpn | grep :123
$ ss -tulpn | grep :123
Sample outputs:

udp        0      0*                           -               
udp        0      0*                           -

Use the sockstat command on a FreeBSD Unix server:
$ sudo sockstat
$ sudo sockstat -4
$ sudo sockstat -4 | grep :123

Sample outputs:

root     ntpd       59914 22 udp4         *:*
root     ntpd       59914 24 udp4         *:*

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


Leave a Comment