How to bind a non-local IPv6 address?

Solution 1:

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.

Solution 2:

The delay is most likely due to IPv6 Duplicate Address Detection. Turning this off would (of course) break the standard, but you might try setting net.ipv6.conf.eth0.dad_transmits to 0 (defaults to 1 on my Ubuntu system):

sysctl -w net.ipv6.conf.eth0.dad_transmits=0

To make permanent:

sudo /bin/bash -c 'echo "net.ipv6.conf.eth0.dad_transmits=0" > /etc/sysctl.d/99-disable-dad-eth0.conf'

Of course, the other option is to just bind to :: (IPv6 all-zeroes, or any IPv6 address) and firewall off the service on interfaces that should not expose it.