For me this is always very frustrating to see companies or individuals doing really weird hostnames that does not scale or translate in to something usefull. Many will know the pretty famous xkcd about finding a suitable hostname. So what should the hostname be?
Theory #
A Hostname is just a DNS record #
Well… It should. But if you keep this in mind, it might become a lot easier. It is a resource on the network and DNS was made to make it easy for humans to get to it with a few words. If it is easier to memorize the IP, then you’re doing something wrong.
Domains #
The host is part of a ‘domain’ or realm. Treat it like such. You can consider using a separate domain if the scope allows it. If you have lots of infrastructure, consider a separate domain. But you can also use a .infra
subdomain. Either works.
Utilize Subdomains #
Either a local domain or public. You can use something like int.example.com
or i.example.com
to split the DNS zone for internal stuff. Then stack the layer even further with acc.i.example.com
. Why?
Searchdomains #
Your host has the option for a searchdomain. It gets this either via dhcp or statically. Lets say all your hosts across your domain have example.com
set as searchdomain. You can omit it in usage. ping host.i
will translate to host.i.example.com
.
Zone Delegation #
In case of migrations or reorganisations you can delegate the whole zone to an other DNS server which is already scoped.
Creating structure #
So now you understand why you should use this approach, you have to come up with a structure that works for you. This is where you should spend some brain-capacity. Are you going to scale world-wide? Do you have many departments?
In my advice always structure like this:
example.com
(treat example.com like production)
- [geo]
- [site]
- int (or i)
- [geo]
- [site]
- acc (or a)
- [geo]
- [site]
- etc... etc
Translates to:
host.site.geo.[sub].domain.tld
Structure by example #
Lets look at some examples. Based on the hostname of the device you know a lot about it already.
rtr-1.ams17.nl.example.com
With this use-case, you could already see many providers using a separate ‘infra’ domain. In this case that works like I explained above. You could also consider this:
rtr-1.ams17.nl.network.example.com
This way you are separating your realm of networking in to a subdomain.
Which also works like this:
lb-1.ams17.nl.servers.example.com
kvm-1.ams17.nl.servers.example.com
Separation #
Why is ams17
not separated with a dash you might ask. Simply because it is a site name (it refers to a datacenter). It could be eqn
(Equinix) as well. Whatever you are already using to identify a site works.
In that case you can even stretch it further; If you are really mad and have lots of separations in one city/geo:
rtr-1.17.ams.nl.network.example.com
Other Examples #
host.lab.example.tld
host.ny.example.tld
host.ny.servers.infra.example.tld
host.[dc-site].servers.infra.example.tld
host.[zipcode].[state].[country].int.example.tld
host.sw.[dc-site].network.example.tld
host.rtr.[dc-site].network.example.tld
Remember that you can scope the searchdomain for each device i.e. infra.example.tld
.
Also do not overdo it. You can always add subdomains.
How to name your host #
OK so this is what you probably here for… How do you name your server? How to hostnames?
The name of the host can be whatever you want it to be. (Ughhh, really!?) You can even use emoji’s in a hostname (please don’t).
What you should do #
Notice how i’m using the hostname to differentiate the function of the device. This is the easiest, but not cool. If the device you’re naming serves multiple functions, give it an easy name.
For example; I have a Grafana/Loki/Prometheus stack on one VM, the name is oppie
. Referring to Oppenheimer, the American Prometheus. Maybe far stretched but it works.
You can also choose to name the host with its make/model. It really depends what domain you are structuring and where you want to differentiate.
asr9k (cisco router)
mx204 (juniper router)
ex4400f (juniper switch)
r720 (dell server)
dl380g9 (hp server)
The Dont’s #
- Do not put “infra” or “testing” in a hostname. It is convoluted. We have created structure in the form of DNS to have this separation.
- Do not use numbers if you are not planning to have more than one of said machine. You can always add a number and change name accordingly.
- Do not use host specific info in the name (e.g. it has 128G ram, what cpu it has etc. Unless it suits your usecase very well)
- Do not use underscores. Use
-
dash as a separator, preferably once. - Do not use long/complex names. Remember, if it is easier to memorize the IP…
And lastly;
- Do not use leading zero’s in a hostname.
Why?
rtr-001.ams17.nl.network.example.com
- Tab-completion sucks with this
- difficult to grep (have to regex)
- are you really getting > 100 routers in ams17 ?
- What if you are getting more than 999 ?