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:
Step 3 – You may also want to find out status of your server and its hostname using hostnamectl command:
hostnamectl status
output:
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:
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):
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:
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:
Modify the HOSTNAME= value to match your FQDN host name. Example:
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:
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:
That’s it for now. Enjoy..
Thanks, but what is the purpose of FQDN? What if I have multiple domains but just one VPS. What would you suggest?
You will need FQDN when installing a Cloudera Hadoop distribution and for numerous other purposes…
Thanks finally something that worked
but what if you do not have a fully qualified domain name?
Thanks you are the best