Another day, another time to use
ssh. Wanting to connect to your server, you begin typing
ssh [email protected] - and darn - what was the server's IP address again? You frantically search your shell's history, but to no avail. You just cleared it yesterday.
This is where hostnames come in. They are identifiers used by devices inside a computer network. Simply put: You can use
yourawesomehostname in place of an IP address. That of course only works if you are able to remember the hostname.
Picking a naming scheme is a good place to start. After all, you want all the hostnames of your laptops, desktop PCs, servers and whatever other devices you manage to follow a pattern. And of course, there's a wiki for naming schemes.
I personally decided on fruits. My main PC is now called
coconut while my primary VPS is called
lychee and my NAS is now named
In the next step, you have to add these hostnames to your machine's
hosts file. The file path varies based on your OS. On Linux, it's
/etc/hosts. Inside the file, you can associate hostnames with specific IP addresses. This is where the magic comes in and why things like
ssh [email protected] can work.
To take this a step further, you can use these simple hostnames only as a secondary, additional hostname. The primary hostname can then be based on a naming scheme containing information about the server. Take a look at this example:
<server type>.<data center location code>.<server provider>. This work well in an environment where you have to manage a lot of servers.
You might also like to take a look at an official guideline from the IETF for naming servers. And don't worry, the document isn't too technical.
That's it for today. Have fun choosing your hostnames.
Now let's get to work:
ssh [email protected] ... Wait - what was the hostname again?