What is a hostname?
A hostname is a human readable name that corresponds to a device. The meaning of ‘hostname’ changes depending on the system; this post will focus on what it means with respect to the internet and the Domain Name System (DNS).
Is a hostname the same as a domain name?
It can be, but not always. For a name to be lucky enough to be a hostname, an internet hostname, and a domain name, it must be resolvable to an IP, be part of the DNS, and follow a specific syntax or pattern (letters, digits, and hyphens, not starting or ending with a hyphen). Pretty hefty qualifications there.
What kind of hostname is not a domain name?
Hostnames that are not a part of the DNS, like ‘mikes-laptop’, are not domain names. You can’t exactly find a system halfway across the world with a name like ‘mikes-laptop’. With 4,292,670 people named Michael in the U.S. alone, you can just imagine. (I looked it up on the internet, that number must be right.) Not all hostnames are internet hostnames; however, all “internet hostnames” ARE domain names.
_help.dyn.com is a domain name but not a hostname
- It doesn’t match the naming conventions for a hostname, but domain name labels can contain any octet.
help is a hostname but not an internet hostname
- It’s not resolvable to an IP and is not part of the DNS
help.dyn.com is an internet hostname and a domain name
So what makes a hostname an internet hostname and domain name?
Hostnames can appear at almost any point in the DNS, with A or AAAA address records identifying hosts. Multiple hostnames can point to a single Internet facing host, and inversely, multiple hosts can be referenced by a single domain name, as long as the DNS is setup to accommodate this. When you go to google.com to search “What is a hostname?”, your browser can be directed to any number of different IP addresses by the DNS, and hit any number of different servers that will direct you your search results – and subsequently to this blog post. In that case, multiple hosts resolve to the hostname google.com. Furthermore, you could have gone to www.google.com, google.com, or even search.google.com and you’d end up in the same place. Each of those Internet hostnames point to the same systems.
How do internet hostnames point to a server?
First, let’s take a look at dyn.com’s records:
If you look in the answer section, you’ll see A and AAAA (IPv4 and IPv6 address) records which point to IPs – unique identifying numbers for Internet facing devices. Furthermore, you see MX (Mail eXchange) records which point to Internet hostnames of mail servers at the dyn.com domain. Finally, you see NS (NameServer) records that point to servers that run the DNS – often described as the phone book of the internet. These systems allow us to use friendly internet hostnames to find servers instead of having to remember IP addresses.
So, what did I do to get those fancy DNS records? I used dig (domain information groper) which will work on any Mac or Linux based machine. On Windows, you can use nslookup. Open a shell* and type in
dig dyn.com ANY. Go ahead… I’ll wait.
What you did was query your local recursive (or stub) resolver on your system for dyn.com. Since you’re already here reading this article, the local resolver has cached, or remembered, the answer. It will continue to remember the answer for the TTL (time-to-live). But what if you type in a domain name you haven’t been to before? Let’s see what happens when we simulate going to a domain name that isn’t cached anywhere up the chain. You can follow along at home by typing
dig +trace help.dyn.com.
No, I’m not drawing ASCII art – this is the output of the dig command, showing you the steps it took to find the the IP address that the internet hostname help.dyn.com maps to.
- My DNS client, dig, queried the local resolver for help.dyn.com. The local resolver then asked the root servers (a nameserver for the root zone of the DNS of the internet) in the top section for the answer.
- The root server then told my recursive resolver the answers for the TLD (Top-Level Domain) authoritative servers for .com.
- Next, the recursive resolver asked the .com TLD authoritative server the exact same question – help.dyn.com and received the answer – the authoritative servers for dyn.com
- Again, the recursive resolver asks the same question, but this time to one of the dyn.com authoritative servers (those are listed as the internet hostnames ns1-ns4 in the image.
- Tired of asking the same question over and over? The recursive resolver is happy to get the A record for help.dyn.com –
184.108.40.206, but it’s not done yet.
- Now, it saves this answer in case you (or your browser, or an application, or any other service) asks again. It will now remember it until the TTL expires.
This is actually pretty neat – to get to any host on the internet, a system can just query any recursive nameserver. As long as that nameserver knows how to find the root servers, it can follow the pattern above and find any host on the Internet given its FQDN (fully qualified domain name).
Wait – what? Another ‘name’?
Yes, a FQDN is a fully qualified domain name. It’s the full Internet hostname used to represent a device in the DNS. They are broken down into parts: [local part].[domain].[tld]. Now you ask – does your computer have a hostname? Yes, it does. In Mac or Linux, type `hostname` in the shell you used above. However, this is not an internet hostname.
You can change this hostname as well, but it could have some undesired consequences, especially if other systems connect to yours using that hostname.
Can I make a hostname point somewhere else?
Well, sure. If you want to.
(but it’s not recommended unless you really know what you’re doing)
Every system has a hosts file. For instance, on my Mac, it’s
/etc/hosts. Anything in this file will be returned before any DNS information is used – but only on your local machine.
Because I work at Oracle Dyn, my hosts file tends to be much larger and more customized than what you see above, but were only interested in the first part of the file. The entire first section is shows local hostname information – IPv4, subnet, IPv6, and IPv6-localnet. Adding additional entries will instruct your system to use those addresses instead of the DNS entries.
Why would you want to do this? Typically it’s used for network debugging, blocking malicious software, and software development.
How long have hostnames been around?
In the mid-1960s, hosts files were used as the sole means to find other systems within ARPANET. As more systems connected, that became cumbersome and a centralized system was developed. Over time, even that became too hard to maintain, and the DNS was designed in 1985. Being a distributed system, the DNS can scale almost infinitely. It’s one of the few computer systems that have been around for over 30 years and it is still in use, practically its original form.
Hostnames in their fully qualified domain name format are unique within the DNS and provide a standardized way to find any internet facing device. You can be creative with hostnames, naming all of your systems based on a theme (I used cereal for many years). You can be extremely organized with your hostnames – essential for large enterprises running hundreds of systems. But most importantly, you now know all about hostnames. Aren’t you glad you asked?