Mapping ::1 to 127.0.0.1

hosts

I am no expert in DNS or IPv6. I am using a brand new Mac with what seems to be the default:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

I have enabled Apache. With the above hosts file, localhost is not working in the browser. From what I have read I think it's ipv6 that I haven't configured Apache for.

What I tried:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             127.0.0.1

Everything works fine now. My question is, is mapping "::1" to "127.0.0.1" ok? Am I breaking/losing something in DNS by doing this. If so, I am not clear how to edit my conf file to allow apache to answer to localhost.

Best Answer

You're not actually mapping ::1 to 127.0.0.1 in this case. You're providing an invalid name for ::1 that is essentially disabling the entry. You can't map an ipv6 address to an ipv4 address - they're not compatible.

If you need localhost resolution for ipv6 to not be enabled, simply comment the ::1 line out, or don't include it at all.