3 ms·
A trailing "." represents the root of the DNS namespace like a leading "/" represents the root of the Linux (or Unix, etc.) filesystem. The root has children l
by adrianmonk 6y ago
A trailing "." represents the root of the DNS namespace like a leading "/" represents the root of the Linux (or Unix, etc.) filesystem.
The root has children like "com", "net", "uk", etc.
There are DNS records at the root level. Try this command:
host -t ANY .
Also, just as Linux searches PATH (in order) when you run a command, the DNS resolver searches a path when you look up a host. (Usually the resolver path is specified by directives in /etc/resolv.conf.) Just as Linux will skip this process if you specify a leading "/", the DNS resolver will skip that process if you specify a trailing ".".
It used to be pretty common to put your organization's domain in /etc/resolv.conf so that you can use the short version of a hostname. If your company is example.com and you have example.com in the DNS search path, you can type a command like "ping www", and it will do the same thing as "ping www.example.com". Most software still supports this, but it isn't used by that many people. (Some organizations don't put their domain in /etc/resolv.conf, and many users don't know they can abbreviate hostnames in this way.)
You would typically use the trailing dot if you want to be sure the DNS lookup doesn't use the search path and checks only against the root of the DNS namespace. You also use the trailing dot in some data files for DNS servers.
In many cases the trailing dot is not necessary, practically speaking, because the DNS resolver has special logic where if you give it a string that contains any dots (not just trailing), the search order is rearranged to try the root first instead of last. (In /etc/resolv.conf, this is controlled by the "ndots" option.)
So if you look up "www.example.com", it will check for the existence of "www.example.com." before it checks for "www.example.com.example.com." instead of the other way around. Which is good because only the first is likely to exist. If you look up "www", it will check for "www.example.com." before it checks for "www.", which again is a good heuristic because again the first is the one that likely exists.