Recommended VPS Complete list of best VPS hosting providers.

Setup FQDN Hostname on CentOS Server

Today’s another basic tutorial for newbies is setting up or change default hostname to Fully Qualified Domain Name (FQDN) format on CentOS 5, 6, and 7 / RHEL 5, 6 and 7 server. I believe somehow you may need to do this task because not all providers are provisioning your servers with hostname in FQDN format as default.

Take Atlantic.net as example, when you are creating a server, they will only ask you to enter a Server Name which is a descriptive name about your server you wish to create. As a result, if I entered “dailyblog” as my Server Name, then default hostname will be also “dailyblog”. So if by any chance you are in the same situation and want to change current hostname to another one? Simply follow these steps below.

What’s FQDN? A fully qualified domain name (FQDN), sometimes also referred to as an absolute domain name, is a domain name that specifies its exact location in the tree hierarchy of the Domain Name System (DNS) – Wikipedia.

Procedure on CentOS 7 / RHEL 7

Step 1 – Login to your server / VPS as root or as a user with root privilege.

Step 2 – Check current hostname:

hostname

It will returns output like this:

2015-06-22_215619

Step 3 – You may also want to find out status of your server and its hostname using hostnamectl command:

hostnamectl status

output:

2015-06-22_215810

Step 4 – Now here’s the magic command to change default CentOS 7 hostname without having to reboot your server:

hostnamectl set-hostname fqdn.host.name

Change fqdn.host.name to your own FQDN hostname. Example:

hostnamectl set-hostname servedby.servermom.org

And the output is:

2015-06-22_220427

So if you issue the hostnamectl status command again, you’ll see it changed. But however you’ll only see it has really changed if you close current session and reopen new SSH session (get out and login back):

2015-06-22_220510

CentOS / RHEL 5, 6, and 7

This procedure can be done on many CentOS distribution.

Step 1 – Login to your server as root or as user with root privilege (sudo)

Step 2 – Check current hostname:

hostname

example:

2015-06-22_215619

Step 3 – Edit network file located at /etc/sysconfig/ using your favorite text editor like vi or Nano. As always, I prefer to use Nano editor.

nano /etc/sysconfig/network

You’ll then see something like this:

2015-06-22_221913

Modify the HOSTNAME= value to match your FQDN host name. Example:

2015-06-22_222002

Now save changes and exit the editor which in Nano it is Control+O then Control+X.

Step 4 – Edit your server hosts file, again, use your favorite text editor:

nano /etc/hosts

Do not forget to set or change the host that is set to your IP address on server.

xxx.xxx.xxx.xxx  fqdn.host.name fqdn

Example again:

2015-06-22_222541

Step 5 – Done, now restart networking service and run the hostname command again:

/etc/init.d/network restart
hostname

Step 6 – Reboot your server to apply hostname changing, then now when you login back you’ll see it changed:

reboot

example:

2015-06-22_222931

That’s it for now. Enjoy..

5 Comments

Add a Comment

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

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.