When you’re managing a web host, there are some things you must do initially. Things like setting your server hostname, timezones and other settings need to be done initially for the server to operate properly.

This brief tutorial is going to show you how to configure CentOS 7 hostname as well as it fully qualify domain name for your server. If you feel like the current hostname assigned to your server doesn’t properly represent the domain, continue below to learn how to change it.

Another thing also is to set the fully qualify domain name (FQDN).

For example, if your server hostname is web01, you can assign a domain to that and write it as web01.mydomain.com. This is the fully qualify domain name for the server.

Setting the fully qualify server name isn’t required, but cool to have especially in environments where filesharing is enabled and the machine hosting the file is a server. Again, you don’t have to do it, but it’s cool to setup.

In the hostname file of most CentOS servers, there’s a line that represents the hostname of the system. It usually begins with the server IP address, the fully qualify domain name and the short server name.

To view our current setup, run the commands below from the terminal console.



cat /etc/hosts

If the server hasn’t been configured and in its original form, it will show localhost as the server name and localhost.localdoman as the fully qualify name.

To change your hostname on CentOS 7, run the commands below to edit the hosts file. Then add a new line with the server IP address, fully qualify domain name followed by the server short name.

sudo vi /etc/hosts

Then add the line below with the IP address of the server, the fully qualify domain name and the server short name.                           web01.mydomain.com                     webo1

This is how the line should look. You can add the new line below the last line in the file and save it. When the file is saved, run the commands below to refresh and apply the changes.

You do not need to restart your computer for the changes to apply. All you have to do is run the commands below.

systemctl restart systemd-hostnamed

After running the commands above, ping the now hostname to to see it respond to the IP address added.

ping web01

It will show the fully qualify domain name.

The one thing to remember is do not delete any line in the file. Just add the new line for the server at the end of the last line and save the file. This tutorial may also apply to other version of CentOS as well as other version of Linux distributions.

That’s it!