Changing the hostname on CentOS

If the hostname setting is incorrect on your CentOS/RedHat/Fedora machine, it's really easy to change the hostname from the command line. There are also GUI tools for doing this but we'll just look at the CLI tools for doing this.


The file /etc/sysconfig/network contains the hostname and will look something like this:

NETWORKING="yes"
GATEWAY="10.1.1.1"
HOSTNAME="www.example.com"

Simply open up the file in your favourite text editor, either as root or using sudo, and change the HOSTNAME value to what you want it to. For example, if we wanted to change www.example.com from the above example to ftp.example.com then you'd end up with the following:

NETWORKING="yes"
GATEWAY="10.1.1.1"
HOSTNAME="ftp.example.com"

This change won't take affect until the next reboot, but you can make the change happen immediately using the hostname command like so:

$ hostname ftp.example.com

Simply issuing the command on its own will return the current hostname, eg

$ hostname
ftp.example.com

You may also need to add/change the hostname in the /etc/hosts file. By default this would look something like this, using our www.example.com example again:

127.0.0.1  www.example.com localhost localhost.localdomain

You would then change it to be like so:

127.0.0.1  ftp.example.com localhost localhost.localdomain
  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

How can I create a database from an sql backup file ?

First, create the database.. /path/to/bin/mysqladmin -u $mysqlusername -p$mysqlpassword create...

How can I see all running processes from my server?

Type the following command from shell prompt.It will display the currently running processes. ps...

Connecting to your Windows server

To connect to your Windows VPS or Dedicated server, you use Remote Desktop Connection. Go to:...

Connecting to your Linux server

To connect to your Linux VPS or Dedicated Server, you need a ssh client.  We recommend...

Memory usage seems too high inside a VPS

There are cases when you may notice that the memory usage is too high inside your VPS without a...