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.
Step 2 – Check current 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:
output:
Step 4 – Now here’s the magic command to change default CentOS 7 hostname without having to reboot your server:
Change fqdn.host.name to your own FQDN hostname. Example:
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):
Step 1 – Login to your server as root or as user with root privilege (sudo)
Step 2 – Check current 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.
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:
Do not forget to set or change the host that is set to your IP address on server.
Example again:
Step 5 – Done, now restart networking service and run the hostname command again:
Step 6 – Reboot your server to apply hostname changing, then now when you login back you’ll see it changed:
example:
That’s it for now. Enjoy..
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:
1
| hostname |
Step 3 – You may also want to find out status of your server and its hostname using hostnamectl command:
1
| hostnamectl status |
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 |
1
| hostnamectl set - hostname servedby.servermom.org |
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:
1
| hostname |
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 |
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:
1
| nano /etc/hosts |
1
| xxx.xxx.xxx.xxx fqdn.host.name fqdn |
Step 5 – Done, now restart networking service and run the hostname command again:
1
2
| /etc/init .d /network restart hostname |
1
| reboot |
That’s it for now. Enjoy..
No comments:
Post a Comment