How to change the host name in Linux

How to change the host name in Linux

1. View the current host name

[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 # Temporarily modify the host name, which will become invalid after shutdown [root@fangjian ~]# hostname
yin

3. Permanently change the host name

1. Method 1: Use the hostnamectl command

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

2. Method 2: Modify the configuration file /etc/hostname and save and exit

[root@fangjian ~]# vi /etc/hostname # Enter vi, delete the old host name, enter the new host name, Esc followed by a colon wq to exit and save the file. # reboot to take effect.

The above is a simple method to change the host name in Linux. If you have any additions, please contact the editor. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Linux host name modification command
  • How to permanently change the host name in Linux
  • How to modify the network card name and host name in Linux
  • Detailed introduction to linux host name configuration

<<:  Why is it not recommended to use index as key in react?

>>:  How to optimize MySQL deduplication operation to the extreme

Recommend

Vue sample code for online preview of office files

I'm working on electronic archives recently, ...

Rounding operation of datetime field in MySQL

Table of contents Preface 1. Background 2. Simula...

How to implement remote automatic backup of MongoDB in Linux

Preface After reading the previous article about ...

Detailed explanation of MySQL database triggers

Table of contents 1 Introduction 2 Trigger Introd...

Mysql master/slave database synchronization configuration and common errors

As the number of visits increases, for some time-...

The problem of form elements and prompt text not being aligned

Recent projects involve the creation of a lot of ...

Cross-browser development experience summary (I) HTML tags

Add a DOCTYPE to the page Since different browser...

What we can learn from Google's new UI (pictures and text)

The most significant website change in 2011 was Go...

Analysis and summary of the impact of MySQL transactions on efficiency

1. Database transactions will reduce database per...

Detailed explanation of Vue two-way binding

Table of contents 1. Two-way binding 2. Will the ...

How to use Dockerfile to build images in Docker

Build the image Earlier we used various images fo...