Detailed explanation of Linux host name modification command

Detailed explanation of Linux host name modification command

Linux change hostname command

1. If you only need to temporarily change the host name, you can use the hostname command.

sudo hostname <new-hostname>

# For example:

sudo hostname myDebian

This command does not change the static hostname in the /etc/hostname file, it only changes the transient hostname. So after restarting the computer it will go back to the old hostname.

2. If you want to permanently change the host name, you can use the hostnamectl command, or use vim to manually modify the /etc/hostname file

The command syntax is:

sudo hostnamectl set-hostname <newhostname>

# sudo vim /etc/hostname

This command will delete the hostname in the /etc/hostname file and replace it with the new hostname.

Content extension :

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 are all the relevant knowledge points introduced this time. If you have any additions, please contact the editor of 123WORDPRESS.COM.

You may also be interested in:
  • How to change the host name in Linux
  • 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

<<:  MySQL 5.6.37 (zip) download installation configuration graphic tutorial

>>:  MySQL 5.7.16 ZIP package installation and configuration tutorial

Recommend

Vue custom v-has instruction, steps for button permission judgment

Table of contents Application Scenario Simply put...

mysql5.6.8 source code installation process

Kernel: [root@opop ~]# cat /etc/centos-release Ce...

Detailed use of Echarts in vue2 vue3

Table of contents 1. Installation 2. Use Echarts ...

Implementation of Docker cross-host network (manual)

1. Introduction to Macvlan Before the emergence o...

Detailed tutorial on deploying SpringBoot + Vue project to Linux server

Preface Let me share with you how I deployed a Sp...

Use pictures to realize personalized underline of hyperlinks

Don't be surprised if you see some kind of und...

How to check if a table exists in MySQL and then delete it in batches

1. I searched for a long time on the Internet but...

DockerToolBox file mounting implementation code

When using docker, you may find that the file can...

Four ways to create objects in JS

Table of contents 1. Create objects by literal va...

Detailed explanation of the production principle of jQuery breathing carousel

This article shares the specific process of the j...

Detailed graphic explanation of mysql query control statements

mysql query control statements Field deduplicatio...

Example of how to deploy Spring Boot using Docker

Here we mainly use spring-boot out of the box, wh...

Use docker to deploy tomcat and connect to skywalking

Table of contents 1. Overview 2. Use docker to de...

CSS to achieve chat bubble effect

1. Rendering JD Effect Simulation Effect 2. Princ...