Atlantic.Net Blog

How to Change Your Hostname in CentOS 5

Atlantic.Net NOC
by Atlantic.Net (68posts) under VPS Hosting
Verified and Tested 2/4/15


In this article, we discuss how to change your server’s hostname in CentOS 5.

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.

If you are running Centos 6.7, see that how-to here; and for Centos 7, click here.


Server running CentOS 5. If you do not have a server, consider a Virtual Private Server from Atlantic.Net.

How to change your hostname in CentOS 5

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:


Sample /etc/sysconfig/network

Sample /etc/sysconfig/network

Sample /etc/sysconfig/network

Sample /etc/sysconfig/network


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:

Sample /etc/hosts

Sample /etc/hosts

At 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
Hostname command

Hostname command

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 and 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 examples of acceptable hostnames:



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

Thank you for following along in this How-To and feel free to check back with us for any new updates or to learn more about our VPS hosting services.

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