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

MySQL startup error InnoDB: Unable to lock/ibdata1 error

An error message appears when MySQL is started in...

Multiple ways to change the SELECT options in an HTML drop-down box

After the form is submitted, the returned HTML pag...

Easyswoole one-click installation script and pagoda installation error

Frequently asked questions When you are new to ea...

Detailed explanation of the correct way to install opencv on ubuntu

This article describes how to install opencv with...

Detailed explanation of Truncate usage in MySQL

Preface: When we want to clear a table, we often ...

How to use fdisk to partition disk in Linux

Commonly used commands for Linux partitions: fdis...

Use CSS's clip-path property to display irregular graphics

clip-path CSS properties use clipping to create t...

How to build svn server in linux

1: Install SVN yum install -y subversion 2. Creat...

How to restore data using binlog in mysql5.7

Step 1: Ensure that MySQL has binlog enabled show...

Analysis of the Principles of MySQL Slow Query Related Parameters

MySQL slow query, whose full name is slow query l...

Detailed explanation of the failure of MySQL to use UNION to connect two queries

Overview UNION The connection data set keyword ca...

Mysql online recovery of undo table space actual combat record

1 Mysql5.6 1.1 Related parameters MySQL 5.6 adds ...