Linux Simple Method for Modifying Hostname

  • 2021-07-18 09:40:56
  • OfStack

1. View the current hostname


[root@fangjian ~]# hostnamectl
  Static hostname: brace
  Pretty hostname: Brace
     Icon name: computer-vm
      Chassis: vm
    Machine ID: 20191225111607875619293640639763
      Boot ID: 25ac5021d229471382a26bea3d351de3
  Virtualization: kvm
 Operating System: CentOS Linux 7 (Core)
    CPE OS Name: cpe:/o:centos:centos:7
      Kernel: Linux 3.10.0-1062.9.1.el7.x86_64
   Architecture: x86-64

2. Temporarily modify the host name


[root@fangjian ~]# hostname yin  # Temporary modification of host name, invalid after shutdown 
[root@fangjian ~]# hostname
yin

3. Permanently modify the host name

1. Method 1: Use the hostnamectl command


[root@fangjian ~]# hostnamectl set-hostname Brace # Permanently set the user name, which will not fail after shutdown 
[root@fangjian ~]# hostname
brace

2. Method 2: Modify configuration file/etc/hostname Save Exit


[root@fangjian ~]# vi /etc/hostname  #  Enter vi , delete the old hostname, enter the new hostname, Esc Post colon  wq Exit Save 
brace                    # reboot Restart takes effect 

The above is linux modifies the host name simple method, if has any supplement may contact this site, thanks everybody to this site support.


Related articles: