Solving “(99: Cannot assign requested address)” with nginx using IPv6 on a KVM VPS running Ubuntu…

Ok, that headline’s a bit of a mouthful.

Basically, I was running into an issue where nginx would not start when the server restarted. However, after it finished booting, I could “service nginx start” and it would come up just fine. Eventually I looked to the error log and found a line with the following attached to an IPv6 address:

(99: Cannot assign requested address)

After a bit of digging, I found a few sources of info ….


Basically, the IP6 addresses have just been assigned and are in a “tentative” state. nginx tries to listen before it’s ready, and the error comes about. Incidentally, this seems to affect Apache users too.

In any case, there are a few things you can try if it’s affecting you. 1 of them worked for me (the other 2 didn’t), but I’ll list them all.

1) Edit /etc/init.d/nginx and plunk the following line in the very top:

post-up while ip -6 addr show tentative | grep . > /dev/null ; do sleep 1 ; done

It’s what worked for me. nginx fired right up on reboots. The downside is that any time you try to “service nginx <anything>”, it’ll hang for a few seconds & spit out a short error (that first line doesn’t really belong) before it does whatever you requested. But it works.


2) Edit /etc/network/interfaces and toss the following line in the inet6 interface definition:

post-up while ip -6 addr show tentative | grep . > /dev/null ; do sleep 1 ; done

Yes, it’s the same line. It did not work for me, but a number of others seemed to have success (I tried it both at the beginning and near the end of the ipv6 block, as I wasn’t positive as to where in the block it should go).


3) Edit /etc/sysctl.conf and add the following:


This came from ServerFault. It didn’t work for me.


Anyway, if you’re having the same issue, those may be worth a try. Not the cleanest solution, but IPv6 adoption is still pretty young so I suppose we’ll all have to muddle our ways through as best we can.

Worth noting that the OpenVZ VPS’s I played with didn’t seem to have this issue.

Please leave a comment if one of those solutions worked for you so that others know what to (and what not to) try. And as always, if you came across an even better solution, I’d love to hear about it!