How do i change hostname?

Posted May 6, 2015 46.4k views
Linux Basics Ubuntu Linux Commands

How do i change the hostname of a running server?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

4 answers

Do the following:

  • Step 1. sudo nano /etc/hosts

  • Step 2. change your-current-hostname to your-new-hostname. Then save the file.

  • Step 3. sudo nano /etc/hostsname

  • Step 4. change currently entered hostname in that file and enter your new hostname. Save the file after.

@thefliik - Sorry for that typo.
/etc/hostsname …should be /etc/hostname.

On CentOS6 I found the following files:
/etc/network : HOSTNAME=ABCD
/etc/hosts : added ABCD to the IPv4 (at the end of the line starting with

After a reboot, all good

Submit an Answer