Bend the Host Name of CentOS 7, and bend the Host Name of CentOS 7

Source: Internet
Author: User

Bend the Host Name of CentOS 7, and bend the Host Name of CentOS 7

In CentOS 6, it is easy to modify the host name.hostnameCommand to permanently modify the Host Name and directly write it into the file/etc/sysconfig/network.

However, in CentOS 7, the host name is not that simple, and it involves some bending.

In CentOS 7, host names are divided into three categories: static (static host name), pretty (nice-looking, easy-to-read host name), and transient (temporary ). Files related to host names in CentOS 7 are/etc/hostnameIt is read during system initialization, and the kernel sets the transient host name based on its content.

Where:

/Etc/hostnameThe static host name in the file takes effect instantly and permanently. Use after modificationhostnameCommand oruname -nYou can directly read the file and initialize it according to the host name of the file after restart.

/Etc/hostnameWhen the file does not have a host name, the kernel will initialize the transientlocalhost.localdomain.

/Etc/sysconfig/networkThe file is invalid.

CentOS 7 host name modification, view hostnamectl command

1. view the Host Name

Hostnamectl # Or hostnamectl status # Or hostnamectl [-- pretty | -- static | -- transient] status

For example, the current host name is "xuexi.longshuai.com ".

[root@xuexi ~]# uname -nxuexi.longshuai.com[root@xuexi ~]# hostname name1[root@xuexi ~]# hostnamectl    Static hostname: xuexi.longshuai.comTransient hostname: name1         Icon name: computer-vm           Chassis: vm        Machine ID: d13bce5e247540a5b5886f2bf8aabb35           Boot ID: d34a4222469e4f1cbe20c27aca174e10    Virtualization: vmware  Operating System: CentOS Linux 7 (Core)       CPE OS Name: cpe:/o:centos:centos:7            Kernel: Linux 3.10.0-327.el7.x86_64      Architecture: x86-64

You can see that the transient has changed after you use the hostname command to modify the host name.

2. Modify the three host names at the same time.

When both pretty and (static | transient) are modified, the simplified section of the pretty name is used as the static host name.

hostnamectl set-hostname NAME

For example:

[root@xuexi ~]# hostnamectl set-hostname name2[root@xuexi ~]# hostnamename2[root@xuexi ~]# cat /etc/hostname name2[root@xuexi ~]# hostnamectl status   Static hostname: name2         Icon name: computer-vm           Chassis: vm        Machine ID: d13bce5e247540a5b5886f2bf8aabb35           Boot ID: d34a4222469e4f1cbe20c27aca174e10    Virtualization: vmware  Operating System: CentOS Linux 7 (Core)       CPE OS Name: cpe:/o:centos:centos:7            Kernel: Linux 3.10.0-327.el7.x86_64      Architecture: x86-64[root@xuexi ~]# hostnamectl  --pretty[root@xuexi ~]#

We can see from the results that only static and transient are changed (kernel Dynamic Maintenance will definitely change), but pretty is not set successfully. This is because the host name "name2" is a name that complies with the host name standard. If you specify a non-standard host name, such as containing special characters, pretty is also set.

For example:

[root@xuexi ~]# hostnamectl set-hostname "name22 name22"[root@xuexi ~]# hostnamectl   Static hostname: name22name22   Pretty hostname: name22 name22         Icon name: computer-vm           Chassis: vm        Machine ID: d13bce5e247540a5b5886f2bf8aabb35           Boot ID: d34a4222469e4f1cbe20c27aca174e10    Virtualization: vmware  Operating System: CentOS Linux 7 (Core)       CPE OS Name: cpe:/o:centos:centos:7            Kernel: Linux 3.10.0-327.el7.x86_64      Architecture: x86-64

The pretty hostname has been changed, and the static hostname is its "simplified version ".

3. modify a host name Type

hostnamectl set-name NAME --statichostnamectl set-name NAME --transienthostnamectl set-name NAME --pretty

Use the example above.

4. Modify the two names at the same time.

hostnamectl set-name NAME --static --transienthostnamectl set-name NAME --static --prettyhostnamectl set-name NAME --transient --pretty

Use the example above. However, when you modify the pretty host name and the other one, the pretty "simplified version" is used ".

5. Modify and view the host Name of the remote host, and use the "-H" or "-- host" option. The connection is based on SSH.

Note: you cannot remotely modify the Host Name of CentOS 5 or 6 because it uses the systemd command to modify the host name.

hostnamectl -H [USER@]HOST set-hostname NAMEhostnamectl -H [USER@]HOST status

For example, use the root user to connect to host 192.168.100.59 and modify its host name.

hostnamectl -H root@192.168.100.59 set-hostname hello59hostnamectl -H root@192.168.100.59 status

 

Back to Linux series article outline: http://www.cnblogs.com/f-ck-need-u/p/7048359.html
Back to website architecture series article outline: http://www.cnblogs.com/f-ck-need-u/p/7576137.html
Back to database series article outline: http://www.cnblogs.com/f-ck-need-u/p/7586194.html
Reprinted please indicate the source: http://www.cnblogs.com/f-ck-need-u/p/8611558.html

Note: If you think this article is not bad, please click the recommendation in the lower right corner. Your support can stimulate the author's enthusiasm for writing. Thank you very much!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.