fbpx

Server Setup

Linux: set hostname properly

by , , revisited on


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

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: domain.com. 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 domain.com. 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.: web1.domain.com, web2.domain.com, etc.

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

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

Set hostname

CentOS 7

echo "web1.domain.com" > /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:

1.2.3.4 web1.domain.com

Replace 1.2.3.4 with public IPv4 address of the machine

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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