April 21, 2014

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.

Print the network node hostname

# 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

1
2
3
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

1
2
3
4
# 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

  • Gunn

    Good god. Thank you! After trying numerous websites, your tutorial and video finally solved my name change issue. Much appreciated

  • Anonymous

    Pleasure!

  • Har

    Thank you so much for your tutorial, it was the missing piece much needed for my cloned virtual box guest machines

  • http://www.mod-page-speed.com Joe

    My Friend,
    I tip my hat to you.. It solved my problem!
    Thanks,
    Joe

  • Lokasgr

    hi!! i have a problem with terminal. When i open it as root the command name is -bash-3.2#

    CentOS release 5.6 (Final)
    Linux ks209884 2.6.38.2-xxxx-std-ipv6-64 #1 SMP Tue Apr 12 17:19:35 UTC 2011 x86

    _64 x86_64 x86_64 GNU/Linux

    server    :
    ip        : 188.165.198.17
    hostname  : ks209884

    -bash-3.2#

    when i use command to chance path dont shows it changes.
    it returns

    -bash-3.2#

    can you help me to solve it??

    Thank you a lot!

  • Anonymous

    At the command prompt paste this and hit enter, does anything happen ?

    # PS1=”[[e[36;1m]u[e[31;1m]@[e[32;1m]h[e[0m]:[e[36;1m]w[e[0m]]# “

  • kris

    Thanks a lot