Server Setup

Linux: set hostname properly

by , , revisited on

We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install NGINX, Varnish, and lots of useful modules for them, this is your one-stop repository to get all performance-related software.
You have to maintain an active subscription in order to be able to use the repository!

Once you get a hold of your new VPS at Linode or DigitalOcean, or dedicated server, the first thing you must do is to set hostname.

Choosing hostname

An immediate decision by many is to use the domain name of primary website to be hosted: While this would work, it is wrong by many reasons.

What is machine’s hostname? The official definition is the following:

The hostname is the name that programs such as mail and web servers use to identify the system that they are running on.

Suggest that you have multiple servers running behind your great startup website, for load balancing purpose. You have set the hostname of each balancing node to domain name of the site: each machine has hostname Then you cannot know easily identify which machine has sent out specific email.

But, if you follow simple naming convention, it will be much easier. Name each balancing node to webX, where X is number of the server: web1, web2, etc.

But what if you have multiple websites and multiple servers? There would still be a confusion.

This leads us to the proper way of setting hostname: use FQDN (fully qualified domain names). We would simply extend the previous naming convention and append the primary domain name of the site to be hosted, i.e.:,, etc.

In case you have one server for anything, its hostname should still be unique and different from primary site domain, i.e.:

Obviously, if you would be using a separate machine for hosting your MySQL server, its hostname would be

Set hostname

CentOS 7

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

Update hosts

Final step in setting the hostname is updating /etc/hosts file.

Add this line at the bottom:

Replace with public IPv4 address of the machine

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.