Jump to content
Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
NickTheGreek

How to Change Hostname in RHEL / CentOS 7.0

Recommended Posts

You have probably needed to change the hostname of your CentOS 7 install for one reason or the other. Changing the hostname in CentOS 7 is now much simpler than ever.

If you are ready open up your terminal and follow through this tutorial, and in less than 10 minutes you will have changed your hostname!

Check Hostname

To check the hostname open your terminal and type the following command:

$ hostname

By default the hostname is localhost.localdomain. To change this you can follow the following steps

Edit /etc/hostname File

The easiest way to change the hostname is to edit the /etc/hostname file. Open your terminal and with your favourite text editor delete localhost.localdomain and change to whatever name you like.

$ sudo vi /etc/hostname

Save changes and then confirm your hostname by using hostname command. If it has not changed then you need to restart the CentOS 7 server.

Using Hostnamectl

Hostnamectl is a tool that is used control the Linux system hostname. You can also use this tool to change the hostname in a few easy steps.

 

First and foremost confirm the hostname by using hostnamectl as follows:

$ hostnamectl status

hostnamectl status

To change the hostname type the command:

$ hostnamectl set-hostname grace

hostnamectl set-hostname

It may be necessary to restart the systemd-hostnamed daemon so that as to reflect the change in Static hostname.

$ sudo systemctl restart systemd-hostnamed

restart systemd-hostnamed

Note: Hostnamectl recognizes three types of hostnames: pretty, static and transient. Pretty is stored in /etc/machine-info and is a human readable format while static hostname is stored in /etc/hostname. Transient hostname is more of a temporary hostname which may take up the static hostname when network connectivity is lost.

Using Nmtui

To change the hostname you can also use the NetworkManager text interface tool (nmtui). This is also another very easy method and fairly straight forward.

From the command line invoke nmtui:

$ sudo nmtui

This will present to you a text user interface like this. Using the arrow keys select Set system hostname and use tab to select OK.

nmtui default

Edit the hostname which by default is localhost.localdomain and change it to whatever you prefer.

default hostname edited hostname

After changing the hostname, choose okay, then the following confirmation message will appear. If the hostname is as you desire you can choose OK. You can confirm changes using the hostname command. authorize nmtui

Using Nmcli

Nmcli is a command line tool for controlling the NetworkManager and can also be used to change the hostname.

To check the hostname with nmcli, type in your terminal:

$ nmcli general hostname

This will print out the hostname to your terminal. By default in CentOS 7 it should be localhost.localdomain.

To change this use the command:

$ nmcli general hostname grace

This will request for your password via a GUI interface. If you are running this command remotely remember to use root or sudo:

$ sudo nmcli general hostname grace

You can then check the hostname with the command hostname or nmcli general hostname.

nmcli usage

Conclusion

See how easy it was? CentOS 7 is now much easier to administer compared to the previous releases.

 

http://linoxide.com/linux-command/change-hostname-in-rhel-centos-7/

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×