Linux Modify Hostname Command Explanation
- 2021-07-22 12:21:48
- OfStack
Linux Modify Hostname Command
1. If you only need to change the host name temporarily, you can use the hostname command.
sudo hostname <new-hostname>
# For example:
sudo hostname myDebian
This command does not change the static hostname (static hostname) in the/etc/hostname file, it only changes the temporary hostname (transient hostname). So rebooting the computer will return to the old host name.
2. If you want to change the hostname permanently, you can use the hostnamectl command or manually modify the/etc/hostname file using vim
The command syntax is:
sudo hostnamectl set-hostname <newhostname>
# sudo vim /etc/hostname
This command removes the hostname from the/etc/hostname file and replaces it with the new hostname.
Content extension:
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 all the relevant knowledge points introduced this time. If you have any supplement, you can contact this site.