ntpd - specify interface that is not the default route

Post date: Feb 10, 2013 12:21:05 PM

On a multi-homed Linux server, which is a machine with two or more routes to a network or networks; in this case, the internet-- one may want to bind certain applications to one interface or the other. In this case I wanted to bind ntpd to an interface that was not default route. One can certainly add some static routes for each of the NTP peers but that can get messy, especially with peers that use round-robin DNS. Therefore, checking the ntpd manpage, one quickly finds:

-I [address | interface name]

Open the network address given, or all the addresses associated

with the given interface name. This option may appear multiple

times. This option also implies not opening other addresses,

except wildcard and localhost. This option is deprecated.

Please consider using the configuration file interface command,

which is more versatile.

With Debian, it sources the options file in /etc/default/ntp, so I added "-I eth1" and restarted ntpd.

$ cat /etc/default/ntp

NTPD_OPTS='-g -I eth1'

It was working, it was only connecting to the NTP peers via eth1 and not the default route, although it was no longer serving ntp for my local network, which is not what I intended. Additionally, about 10 minutes later, ntpd segfaulted.

[334743.074156] ntpd[31953]: segfault at 737c ip 000000000040f3f4 sp 00007fffee7ee990 error 4 in ntpd[400000+7c000]

The program was not compiled with debug symbols so I could not quickly look into the problem. I reverted the change to the ntp options file and tried the interface directive, just to see if that would make any difference:

$ cat /etc/default/ntp


$ grep ^interface /etc/ntp.conf

interface listen eth1

I restarted ntpd and again, 10 minutes later..

[523847.752126] ntpd[21583]: segfault at 737c ip 000000000040f3f4 sp 00007fff5c0fbcc0 error 4 in ntpd[400000+7c000]

The same issue.

The correct fix that ended up working:

$ grep ^interface /etc/ntp.conf

interface drop eth2

interface listen eth0

interface listen eth1

Where eth0 is the local network.

Where eth1 is the secondary interface but not the default route.

Where eth2 is the default route.

The default route is no longer used for ntp traffic and eth0 serves local ntp client requests.