Skip to content

CentOS 5 Change Hostname

In this CentOS tutorial we will be showing you how to find and change the hostname of your system.

The assumption is that you are running as root and have a basic understanding of the software required but if you follow this tutorial you should be able to complete the task successfully.

Let us begin by finding the CentOS systems fully qualified domain name (FQDN) by seeing how it identifies itself.

# uname -n
centos01.how2centos.com

Show the systems DNS domain name

# dnsdomainname 
how2centos.com

There are a couple of ways to change the hostname.

Edit /etc/sysconfig/network

# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=centos01.how2centos.com

or run System Config

# system-config-network

Select Edit DNS configuration

âââââââ⤠Select Action âââââââ
  â
  â  Edit a device params
  â  Edit DNS configuration
  â
  â
  â
  â  âââââââââââââ  ââââââââ
  â  â Save&Quit â  â Quit 
  â  âââââââââââââ  ââââââââ
  â
  â
  âââââââââââââââââââââââââââââââ

  ââââââ⤠DNS configuration âââââââ
  â
  â
  â  Hostname      centos01.how2ce
  â  Primary DSN   10.0.0.10______
  â  Secondary DNS _______________
  â  Tertiary DNS  _______________
  â  Search        how2centos.com_
  â
  â     ââââââ  ââââââââââ
  â     â Ok â  â Cancel â
  â     ââââââ  ââââââââââ
  â
  â
  ââââââââââââââââââââââââââââââââââ

Edit the hostname and select OK and then Save&Quit

Dont forget to change the hostname in your hosts file

# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       centos01.how2centos.com centos01 localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6

However we’re not finished. The machine wont normally see the updated hostname until about it reboots, but we can force it to update.

# source /etc/sysconfig/network
# hostname $HOSTNAME