What is a server hostname and how to set it up

The hostname is an essential part of your server. It allows applications to identify on which system they are being executed. So it’s quite logical that you would want to set it up to your taste. And that’s exactly what I’m going to show you today.

NOTE: This guide has been written for Debian based systems, like Ubuntu.

Choosing your server hostname

Everyone has their own preferences when it comes to their server hostname. Some name them after planets, Gods, desserts or any other group. So feel free to choose your own. Just be sure that it’s easy to type !

The Setup

The first thing you want to do is to SSH to your server. Then set your server hostname using the following command (of course, you need to replace “technoreply” with a name of your choice) :

$ echo "technoreply" > /etc/hostname
$ hostname -F /etc/hostname

The first command will store your hostname in a convenient file, while the second command will read your hostname from that file. Since your hostname is now stored in the correct file, it will persist even after you reboot your server.

Now you need to test your new server hostname. There are two commands for that :

$ hostname
technoreply
$ hostname -f
technoreply

The first command shows your unqualified hostname and the second one shows your fully-qualified domain name (FQDN). The FQDN is used by mail servers and such.

As you can see, “technoreply” is not a proper FQDN (there is no TLD). And if you try sending emails, you will notice that it will be very slow. Sometimes it won’t get sent at all.

To fix it, we simply need to edit our hosts file. So open up /etc/hosts and add the following line :

127.0.0.1    technoreply.com technoreply

Notice that the FQDN is first. This is crucial!

Now you have your server hostname setup like it should. If you test it out, you should see this :

$ hostname
technoreply
$ hostname -f
technoreply.com

Happy hacking !

0 Comments to “What is a server hostname and how to set it up”

Leave a reply