CentOS

How to change hostname on centos

To change hostname in centos, here is how to do

Temporary hostname change (this will be reseted after reboot)
hostname newhostname

Permanent hostname change
nano /etc/sysconfig/network

This is from one of my vps

NETWORKING=”yes”
GATEWAYDEV=”venet0″
NETWORKING_IPV6=”yes”
IPV6INT=”no”
IPV6_DEFAULTDEV=”venet0″
HOSTNAME=”namhuy.org”

Change hosts file
Change the host that is related to your main IPaddress for your server, this is for internal networking
nano /etc/hosts

127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 localhost4
# Auto-generated hostname. Please do not remove this comment.
xxx.xxx.xxx.xxx namhuy.org namhuy
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

After saving the file, you should restart network service
service network restart
or
/etc/init.d/network restart

Check your hostname again to make sure it has been update
hostname.

Related Articles

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button