Log in

Login to your account

Username *
Password *
Remember Me

Centos: How to Set Hostname in Centos

Setting the hostname in CentOS (RHEL).

Sometimes during setup of your CentOS system you forget to set the hostname of the server, or you may get situations where you need to change the hostname. This quick tutorial will show you just how easy it is to do this.

Firstly, check the current hostname by entering the command:

# hostname
localhost.localdomain

You can also check hostname by issuing following command:

# sysctl kernel.hostname
kernel.hostname = localhost.localdomain

You can temporarily change hostname by issuing following command, but upon reboot, it will revert to its previous setting

# hostname myservername.domain.com

While this temporary change maybe useful for troubleshooting, to make it permanent, just change the following network file at /etc/sysconfig/network

vi /etc/sysconfig/network

It will look something like:

NETWORKING=yes
HOSTNAME=localhost.localdomain

Hit "i" to insert and change the HOSTNAME value to your FQDN, such as myservername.domain.com

NETWORKING=yes
HOSTNAME=myservername.domain.com

Hit Escape, then :wq to save and exit.

Check that the hostname is now set:

# hostname
myservername.domain.com
# sysctl kernel.hostname
kernel.hostname = myservername.domain.com

Finally, log out and back in using a new session and you'll see you're now logged on as root@myservername

To properly check, reboot your server to see that the change is now permanent.

Follow Us

Mailing List

We're rebuilding a secure form to be relaunched soon.

100nz 125x125

© 2017 Inlet Technologies. All Rights Reserved.

Please publish modules in offcanvas position.