Atlantic.Net Blog

How to Change Your Hostname in CentOS 6.7

Atlantic.Net NOC
by Atlantic.Net (68posts) under VPS Hosting

Verified and Tested 8/25/15


In this article, we discuss how to change your server’s hostname in CentOS 6.7, is a label given to a device that is connected on a network.

Note: The scope of this article does not extend to updating your DNS name, so if you want your server reachable via its DNS name, you will still need to ensure DNS is configured correctly.


Server running CentOS 6.7  If you do not have a server, consider spinning up a powerful and affordable virtual private server from Atlantic.Net.

Modify your hostname in CentOS 6.7

If you’d like to change your CentOS server’s hostname, you’ll need to change it in a few places.

Open up the /etc/sysconfig/network file with your text editor of choice:

sudo vim /etc/sysconfig/network

Change the HOSTNAME argument to the hostname you’d like to use. Here, we’ll be changing the old hostname of ‘bespin’ to ‘endor’. See below for more information on valid hostnames:

Change hostname in Centos
Change hostname in Centos

This change will take effect the next time you reboot your server. Before you do, though, you might want to also add the hostname to your /etc/hosts file.

Again, with your text editor of choice:

sudo vim /etc/hosts

In this instance, we’ll add our new hostname ‘endor’ to the entry for the loopback address (and for fun, for the IPv6 loopback). We might also add an entry for an IP address configured on this server:

Change hostname in CentosAt this point, the next time you reboot your server, your new hostname would show up in your command prompt and would also show up with the ‘hostname’ command. If you would rather not reboot your server, you can change the hostname with the ‘hostname’ command:

sudo hostname yourhostname

Change hostname in Centos

You may change the hostname with this command alone, but the next time you reboot your server, it would not be persistent and would load whatever hostname is still in the /etc/sysconfig/network file.

Also, you may notice that the hostname in your command prompt hasn’t changed. If you’re the sort who’s going to be annoyed by that (or, if you’d like to avoid the confusion of seeing the old hostname in the command prompt), then log out of the current session. When you log back in, the new hostname will show up in the command prompt.

One other caveat: until you do reboot your server after a hostname change, you may also notice that your logs still use the old hostname.

Valid Hostname Restrictions

In each of these configurations, you’ll need to be sure your hostname conforms to the standards for FQDNs (Fully Qualified Domain Names). The ASCII letters a – z, the digits 0 – 9, and the hyphen (‘-‘) are the only characters acceptable (the first character, however, cannot be a hyphen). You may also find it necessary (or useful) to include the domain name as well, in which case you would then also use periods (dots) to separate the hostname and the domain name (and top-level domain). So the following would be acceptable examples:



The whole hostname should be no more than 255 characters (see RFC1123).

What Next?

With that, you now have a server with a hostname. Thank you for following along and feel free to check back with us for further updates, or check out our other CentOS guides.

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year

Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year

New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4


London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom