Tuesday 22 September 2015

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 2Check current hostname:
1
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:
1
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:
1
hostnamectl set-hostname fqdn.host.name
Change fqdn.host.name to your own FQDN hostname. Example:
1
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:
1
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.
1
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:
1
nano /etc/hosts
Do not forget to set or change the host that is set to your IP address on server.
1
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:
1
2
/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:
1
reboot
example:
2015-06-22_222931
That’s it for now. Enjoy..

No comments:

Post a Comment