How To Setup Hostname On CentOS 6

Checking your Linux host name

First, see if your host name is set correclty using the following commands:

#uname -n
#hostname -a
#hostname -s
#hostname -d
#hostname -f
#hostname

If the above commands return correctly with no errors then all may be well; however, you may want to read on to verify that all settings are correct.

There are 4 steps in a hostname change, luckily all the steps are easy.

How To Setup Hostname On CentOS 6


Open the /etc/sysconfig/network file with your favorite text editor. Modify the HOSTNAME= value to match your FQDN host name.
# nano /etc/sysconfig/network

add this line:
NETWORKING=yes  
HOSTNAME=myserver.yourdomain.com 
GATEWAYDEV=eth0  
GATEWAY=192.168.1.21 

1. edit your hosts File


Change the host that is associated to your main IPaddress for your server, this is for internal networking (found at /etc/hosts):
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.21      myserver.yourdomain.com       myserver

2. Run Hostname


The "hostname" command will let you change the hostname on the server that the commandline remembers, but it will not actively update all programs that are running under the old hostname.
# hostname myserver.yourdomain.com

3. verify your hostname


# hostname

4. Restart your network


At this point all the necessary changes that needed to be made have been made, you will want to restart networking on your server to make sure that changes will be persistent on reboot:
# /etc/init.d/network restart

Troubleshooting


sometimes hostname not perfectly changed, you can check and verify with command
sysctl kernel.hostname

and change your kernel hostname
sysctl kernel.hostname=myserver.yourdomain.com

Enjoy..
Previous
Next Post »