I upgraded a couple of days ago to IPv6 on my local test machine and since then I've been experiencing some issue with connecting to my local PostgreSQL server.
I set the host to 'localhost', which worked fine using IPv4. While using IPv6, there is a 1:150 chance that the connection fails (here is a testcase for all unix systems, and here is another one for all other systems (requires psycopg2 and python3)).
As it turns out it is because the loopback interface (lo0) is configured like this:

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    inet6 ::1 prefixlen 128 
    inet netmask 0xff000000 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1  # line 5
    nd6 options=1<PERFORMNUD>

Line 5 is especially interesting. It says use IP address fe80::1 for connections (and which is actually used about every 150th time).
Is it safe to allow all connections (without password) from fe80::1 or did my PC just happen to be number one on the local network? Can my IP change when I'm on another network (I used to on IPv4 but that changed occasionally depending on where I am).
If other computers can also use fe80::1, how can I prevent postgresql from connecting to my server using that address? If I change the host to "::1", will postgresql even work on networks (routers) that don't support IPv6 / haven't IPv6 enabled? Or do I need to use IPv4 (i.e. for 100% stable connection?

Additional tags: IPv6, loopback (Sorry I can't create tags on my own, yet).

  • What operating system and version is this? Kind of crucial info. Seems to me like your resolver is busted; returning fe80::1 for localhost is insanity. Aug 17 '14 at 13:21
  • No, the resolver isn't busted; the IP stack is busted. The loopback interface is not intended to have any link-scope address other than ::1. Unfortunately RFC 4007 is poorly written and this requirement is not made clear enough. Windows and Linux get it right; OS X (which appears to be the OS in use here) doesn't. Aug 18 '14 at 1:01
  • It might be because it's a developer preview (Yosemite)... I found out that fe80::1%lo0 localhost is in /etc/hosts Can I remove that line safely? Or might I damage the system when booting (as described in the commend about)?
    – Matt3o12
    Aug 18 '14 at 6:13
  • 1
    There's no need for that to be in there. The only addresses that should be resolving to localhost are and ::1. Aug 24 '14 at 15:56

So this is almost certainly a bad configuration in ip address resolution. As you mention, you have a line resolving localhost to your external ipv6 address. Yes, this should be removed, or changed from fe80::1 to ::1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.