Linux – How to bind a non-local IPv6 address

bootip addressipv6linux

Is there an equivalent of net.ipv4.ip_nonlocal_bind for ipv6 ? Need to start my nginx on boot on such an IP…

My Ubuntu doesn't have this IPv6 assigned on eth0 quickly enough despite this /etc/network/interface :

iface eth0 inet6 static
    address 1:2:3:4::5
    netmask 64

During boot :

Starting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
[emerg]: bind() to [1:2:3:4::5]:80 failed (99: Cannot assign requested address)

I need to run /etc/init.d/nginx restart a few seconds after boot to make things work :-/

NB : 1:2:3:4::5 is used here only for demo, i have a valid IPv6 address on my server.

Best Answer

The net.ipv6.ip_nonlocal_bind sysctl was added in kernel 4.3, so if you're running a more bleeding-edge system, you can now solve this problem directly with the sysctl, rather than working around the problem with init script hacks.