ntpd 配置为 IPv6,不绑定 IPv6 端口

ntpd 配置为 IPv6,不绑定 IPv6 端口

我在 CentOS 7.4 上有以下 /etc/ntp.conf:

# /etc/ntp.conf: Ansible managed

# drift file
driftfile /var/lib/ntp/drift

# restrictions
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1

# preferred servers
server 0.centos.pool.ntp.org iburst prefer
server 1.centos.pool.ntp.org iburst prefer
server 2.centos.pool.ntp.org iburst prefer
server 3.centos.pool.ntp.org iburst prefer

# fallback servers
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst

# listen only on local interfaces
interface ignore wildcard
interface listen 127.0.0.1
interface listen ::1

# Disable the monitoring facility to prevent amplification attacks; see CVE-2013-5211
disable monitor

但是,我只看到它绑定在 IPv4 上:

[root@0c6790c4704c /]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
udp        0      0 127.0.0.1:123           0.0.0.0:*                           918/ntpd

这是日志:

Jan 08 01:34:05 0c6790c4704c systemd[1]: Starting Network Time Service...
Jan 08 01:34:05 0c6790c4704c ntpd[918]: proto: precision = 0.064 usec
Jan 08 01:34:05 0c6790c4704c ntpd[918]: 0.0.0.0 c01d 0d kern kernel time sync enabled
Jan 08 01:34:05 0c6790c4704c systemd[1]: Started Network Time Service.
Jan 08 01:34:05 0c6790c4704c ntpd[918]: ntp_io: estimated max descriptors: 65536, initial socket boundary: 16
Jan 08 01:34:05 0c6790c4704c ntpd[918]: Listen normally on 0 lo 127.0.0.1 UDP 123
Jan 08 01:34:05 0c6790c4704c ntpd[918]: Listening on routing socket on fd #17 for interface updates
Jan 08 01:34:07 0c6790c4704c ntpd[918]: 0.0.0.0 c016 06 restart
Jan 08 01:34:07 0c6790c4704c ntpd[918]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Jan 08 01:34:07 0c6790c4704c ntpd[918]: 0.0.0.0 c011 01 freq_not_set

有什么我忽略的吗?

答案1

检查是否/etc/default/ntp包含NTPD_OPTS='-4 -g'

该选项-4告诉 ntpd 仅监听 ipv4 。

答案2

我有一个特殊的用例:我在 Docker 中运行虚拟机(阅读:常规 systemd init 进程)(参见naftulikay/centos-vm),并且主机系统没有启用 IPv6 支持。

我发现文档传递--ipv6给 Docker 守护进程将启用 IPv6 支持,所以我尝试了这个并得到以下结果:

Error starting daemon: Error initializing network controller: Error creating default "bridge" network: could not find an available, non-overlapping IPv6 address pool among the defaults to assign to the network

在容器内,ifconfig不显示 IPv6 地址:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 7923  bytes 51083816 (48.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6941  bytes 400410 (391.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

因此,毫不奇怪,如果没有关联的 CIDR 块,IPv6 将无法工作。我想阅读文档以获取有关如何设置的更多信息。

相关内容