Need to change your hostname on CentOS 6? Here’s how!

So, sometimes when you are creating your system you may enter the hostname wrong, or perhaps you want to change a system’s hostname temporarily. Either way, the way to do this is rather simple.

 

Temporary Fix

Type the following command into your Terminal to view the current hostname; hostname . To temporarily change (aka, upon reboot you will lose these changes) type in;

hostname <newhostname>

Clarification: The hostname command temporarily allows you to change your hostname. You can simply type hostname new.example.com and then run service network restart.
You do not need to restart if you use the hostname command. By typing hostname new.example.com, you change your systems hostname temporarily. In your SSH session or CLI screen, you may still see that it’s listed as user@old.example.com, just logout of your existing SSH session and log back in. You’ll now see user@new.example.com.

Permanent hostname change on RedHat based systems

To make a permanent change, you must use your network file.

This can be found in /etc/sysconfig/network which is read on system boot.

Step 1: Vi /etc/sysconfig/network

Step 2: Change the value hostname to desired new hostname.

NETWORKING=yes
HOSTNAME="change.me.org"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"

Step 3: Save & exit with :wq! 

Step 4: Reboot your network service.

service network restart

Step 5: Verify hostname has changed by typing hostname.

Doing this means the next time you restart your system, your hostname will now permanently be change.me.org.

However, if you did not do hostname change.me.org to change it (even though the hostname is only temporary if not utilized in conjunction with updating the main file), then you will need to restart to see the changes reflected.



Share this post


Comments