大网数据广告活动
服务器运维问答

Services attempt to bind to IPv6 address before it comes up

· 52CE 我爱测

I have a couple of services on Ubuntu 23.04, BIND and Nginx, which are configured to bind to specific IPv6 addresses. However, they fail to start because systemd attempts to start them before the IPv6 addresses come up via DHCPv6…

问题原文

原帖链接 · triatic · CC BY-SA 4.0

I have a couple of services on Ubuntu 23.04, BIND and Nginx, which are configured to bind to specific IPv6 addresses. However, they fail to start because systemd attempts to start them before the IPv6 addresses come up via DHCPv6. From my logs I believe the DHCPv6 addresses come up two seconds after DHCPv4.

I can manually restart the services after boot to get them to bind to the IPv6 addresses, but what is the best way to halt their start until IPv6 comes up?

已采纳解答

原帖链接 · u1686_grawity · CC BY-SA 4.0

Linux supports an IP_FREEBIND socket option that programs can enable before trying to bind to a specific address. Neither nginx nor BIND support this natively, but net.ipv6.ip_nonlocal_bind sysctl can enable this system-wide (which may be slightly risky as it means bind() will never fail even when it should).

If you're using systemd-networkd (even if indirectly via netplan), there is a service that you can have in a unit's After= whose only purpose is to wait for all network interfaces to be configured. (NetworkManager has a similar one.) Normally you use it through network-online.target but it can also be used directly:

  • a) Indirectly (the usual way):

    # systemctl enable systemd-networkd-wait-online
    # systemctl edit named
    [Unit]
    Wants=network-online.target
    After=network-online.target
  • b) Directly:

    # systemctl edit named
    [Unit]
    Wants=systemd-networkd-wait-online.service
    After=systemd-networkd-wait-online.service

Generally though, I'd prefer binding to the wildcard address and using the firewall (nftables) to limit access to the service. (I've already seen – and abused – a system that bound its services to addresses of interface A, but did nothing in its firewall to prevent packets from interface B to be routed to those addresses.)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-10-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。