10

I am new to unmanaged VPS servers and in addition IPv6. Is it necessary to include 127.0.0.1 AND ::1 for localhost in /etc/hosts files for IPv6 enabled servers, or is ::1 alone enough?

filmoreha
  • 221
  • 1
  • 3
  • 7

5 Answers5

9

Yes, 127.0.0.1 should be left. IPv6 is enabled, but IPv4 is still used.

Sirch
  • 5,697
  • 4
  • 19
  • 36
  • So I should include the following in my hosts file? 127.0.0.1 localhost ::1 localhost – filmoreha May 02 '12 at 13:13
  • Yes, you should keep both the ipv4 and ipv6 localhost addresses – Sirch May 02 '12 at 13:18
  • Here's another reason you should keep both on Windows: [Fix Google Chrome slow or hanging resolving host](https://markshust.com/2019/12/17/fix-google-chrome-slow-hanging-resolving-host/) – Tore Nestenius Mar 23 '20 at 09:33
5

You didn't mention which OS you are using.

On Windows systems, the name resolution of localhost is handled by the system and those entries are not needed in the hosts file. This is even explicitly mentioned in that very same file:

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
Massimo
  • 68,714
  • 56
  • 196
  • 319
  • "is handled by the system", but how do I configure it? Where can I find the DNS settings which handles localhost name resolution? (in my case I'm running Windows 10) – Redoman Dec 13 '19 at 17:39
  • is handled by the system, but where ? in which file at which level? Best regards. – Lluthus Apr 25 '21 at 16:14
4

Leave the hosts file alone. Fiddle with it and you may break something. For example, if you remove the 127.0.0.1 don't be too surprised if anything that uses localhost fails.

John Gardeniers
  • 27,262
  • 12
  • 53
  • 108
  • I was curious about 120.0.0.1 and ::1 because I had never seen ::1 before and it (along with an IPv6 address) were the only things in my hosts file. Ended up cleaning things up a bit to include 127.0.0.1 as well. – filmoreha May 07 '12 at 00:55
  • @filmoreha, I suspect that's a typo but there was no mention of 120.0.0.1. You also need to consider that a hosted environment, even an unmanaged one, will have certain requirements for monitoring purposes, which is another reason to be cautious of modifying things like the hosts file. – John Gardeniers May 07 '12 at 02:23
  • Thanks, that was definitely a typo. I will keep what you said about monitoring in mind, hadn't thought about that! – filmoreha May 07 '12 at 02:49
0

Adding anything to /etc/hosts is not necessary, but really helps, so it will be pretty useful to add both (IPv4 and IPv6) records. After all, it is not expensive in any sense (10 seconds on each won't kill you day), but you'll know this part is done completely.

Alexander
  • 724
  • 2
  • 11
  • 19
-3

On my mac, I could not access localhost. When I commented out the line "::1 localhost", I was able to access localhost again.