←back to thread

.localhost Domains

(inclouds.space)
301 points todsacerdoti | 1 comments | | HN request time: 0s | source
Show context
EGreg ◴[] No.43644409[source]
Wow! Today I learned that you can have subdomains of localhost. Never realized it!
replies(1): >>43644498 #
jeroenhd ◴[] No.43644498[source]
.localhost is in the same list as .example and .invalid when it comes to reserved names: https://datatracker.ietf.org/doc/html/rfc2606

It's a neat trick, but it comes with some caveats. For instance, `localhost` often resolves to both 127.0.0.1 and ::1, but `.localhost` is described in RFC2606 as "traditionally been statically defined in host DNS implementations as having an A record pointing to the loop back IP address and is reserved for such use". In other words, your server may be binding to ::1 but your browser may be resolving 127.0.0.1. I'm sure later RFCs rectify the lack of IPv6 addressing, but I wouldn't assume everyone has updated to support those.

Another neat trick to combine with .localhost is using 127.0.0.0/8. There's nothing preventing you from binding server/containers to 127.0.0.2, 127.1.2.3, or 127.254.254.1. Quite useful if you want to run multiple different web servers together.

replies(1): >>43644539 #
EGreg ◴[] No.43644539[source]
But is "foo.localhost" a valid domain name, for cookies and such?
replies(1): >>43644730 #
jeroenhd ◴[] No.43644730[source]
The RFC treats .localhost as a full TLD. I believe Windows does as well, as does Ubuntu (using default systemd-resolved), but macOS doesn't seem to resolve .localhost by default, necessitating the host file trickery.

Of course, in the early internet, the difference between a TLD and a host name weren't quite as clear as they are right now.

replies(2): >>43644936 #>>43645959 #
1. EGreg ◴[] No.43644936{3}[source]
We still need the Public Suffix List because of how inconsistent it was