SysAdmin

CentOS / RHEL – 7 How to set hostname permanently

JJ
Jobin Joseph · Founder and CEO
·Published 30 November 2015·1 min read

Issue

Solution

In CentOS / RHEL-7 you need to use the hostnamectlcommand line tool to update the hostname – To set the hostname permanently, issue the below command,

hostnamectl set-hostname  server1.jobnix.in 
[root@server1 ~]# hostnamectl
   Static hostname: server1.jobnix.in
         Icon name: computer-vm
           Chassis: vm
        Machine ID: e71b5f04137d4d99a31037f13c61afec
           Boot ID: fd8cbc3d1f14476e829aa57aa05e4c9b
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.20.1.el7.x86_64
      Architecture: x86_64
hostnamectl [OPTIONS...] COMMAND ...

Query or change system hostname.

  -h --help              Show this help
     --version           Show package version
     --transient         Only set transient hostname
     --static            Only set static hostname
     --pretty            Only set pretty hostname
  -P --privileged        Acquire privileges before execution
     --no-ask-password   Do not prompt for password
  -H --host=[USER@]HOST  Operate on remote host

Commands:
  status                 Show current hostname settings
  set-hostname NAME      Set system hostname
  set-icon-name NAME     Set icon name for host
  set-chassis NAME       Set chassis type for host
Jobin Joseph
Jobin Joseph, Founder and CEO
5x AWS Certified, ISO 27001:2022 Lead Implementer, 17+ years building cloud infrastructure for regulated industries.
About Jobin →

Reading this because your AWS bill or uptime is a problem?

30 minutes, direct with the founder, no sales pitch: one specific recommendation for your AWS workload.

Book a free 30-minute review
30 min Free Consultation →