Skip to content
Home » Linux » How to Change HostName on Enterprise Linux 7

How to Change HostName on Enterprise Linux 7

In CentOS 7, it is slightly different from CentOS 6 on changing hostname (How to Change HostName on Enterprise Linux 6.5). You don't have to modify /etc/sysconfig/network anymore, instead, you should modify a new file /etc/hostname.

There're 3 files need to be modified in order to change hostname.
  1. The hostname file
  2. [root@localhost ~]# vi /etc/hostname
    primary01.example.com

  3. The interface configuration file.
  4. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
    TYPE="Ethernet"
    BOOTPROTO="none"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="yes"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"
    NAME="eth0"
    UUID="..."
    ONBOOT="yes"
    IPADDR0="10.12.13.123"
    PREFIX0="8"
    GATEWAY0="10.0.0.1"
    DNS1="8.8.8.8"
    DOMAIN="example.com"
    HWADDR="..."
    IPV6_PEERDNS="yes"
    IPV6_PEERROUTES="yes"

  5. The hosts file
  6. [root@localhost ~]# vi /etc/hosts
    127.0.0.1   primary01 primary01.example.com localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         primary01 primary01.example.com localhost localhost.localdomain localhost6 localhost6.localdomain6

Now, you can restart your server to verify the results.

Further reading - How to Change DNS on Enterprise Linux 6.5

Leave a Reply

Your email address will not be published. Required fields are marked *