Skip to content

localhost

Prefer 127.0.0.1 over localhost. See this short video on why. Short story:

  • localhost usually resolves to multiple addresses: IPv6 (::1) and IPv4 (127.0.0.1).
    • Some programs may not even try the IPv4 version, so if the IPv6 one fails, then that’s it, the whole program fails. This is what bit me on 1/22/24 when I couldn’t connect to my database due to some dependency changing.
    • Even if the program tries the IPv4 version, it takes time to try the IPv6 address and then fail.
    • Even if the IPv6 address doesn’t fail, it still has to perform a look-up to resolve the name to an address (I suspect this is a very minor reason for why not to use localhost)