How to Change Hostname on CentOS 6.6

This article shows step-by-step how to to change hostname on CentOS 6.6 from the default name localhost.localdomain to server.linglom.localdomain as example.

Step-by-step to change hostname on CentOS 6.6

  1. On CentOS 6.6, type the command below to see the current hostname. The default name is localhost.localdomain.
    hostname

    View hostname on CentOS 6.6

  2. Edit /etc/sysconfig/network by type the command below.
    vi /etc/sysconfig/network

    Edit /etc/sysconfig/network on CentOS

  3. Modify HOSTNAME to the value that you want.
    NETWORKING=yes
    HOSTNAME=server.linglom.localdomain

    Note: To modify file with vi editor, press i to enter edit mode and make changes as you want. Once finish editing, press ESC + : (colon) and type wq to quit vi editor and save changes to the file.
    Modify hostname on CentOS

  4. Next, edit /etc/hosts by type the command below.
    vi /etc/hosts

    Modify hostname on CentOS

  5. Add a new line with IP address as 127.0.0.1 for the new hostname.
    127.0.0.1      localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1            localhost localhost.localdomain localhost6 localhost6.localdomain6
    127.0.0.1      server.linglom.localdomain

    Edit /etc/hosts on CentOS

  6. Save the file and reboot the system by type:
    shutdown -r now

    Reboot CentOS

  7. After reboot, hostname is now changed to new value.
    View hostname on CentOS

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.