Hacker News new | ask | show | jobs
by amckinlay 2950 days ago
.localhost is the loopback IP on most resolvers, though.
1 comments

"localhost" by itself is, but second-level domains (ex.: laptop.localhost) aren't, at least not anywhere I've tried it.
In a well-configured machine second-level domains for .localhost are also supposed to loopback, per the RFC.

(It's useful as a development tool as you can Virtual Host project1.localhost and project2.localhost to different in development sites if your OS and server support it, which tend to be in similar ways to how they generally support Virtual Hosts.)

RFC6761 says:

6.3. Domain Name Reservation Considerations for "localhost."

   The domain "localhost." and any names falling within ".localhost."
   are special in the following ways:

   1.  Users are free to use localhost names as they would any other
       domain names.  Users may assume that IPv4 and IPv6 address
       queries for localhost names will always resolve to the respective
       IP loopback address.
[...]

   3.  Name resolution APIs and libraries SHOULD recognize localhost
       names as special and SHOULD always return the IP loopback address
       for address queries and negative responses for all other query
       types.  Name resolution APIs SHOULD NOT send queries for
       localhost names to their configured caching DNS server(s).
And goes on to specify how resolvers, authoratitive DNS servers, registrars, etc. should behave.

This is implemented on my machine at least by systemd_resolved, see https://github.com/systemd/systemd/blob/master/src/resolve/r... which returns ::1/127.0.0.1 for any record for which which is_localhost is true (defined in https://github.com/systemd/systemd/blob/master/src/basic/hos...).