CentOS 7 Modify hostname

Source: Internet
Author: User

In CentOS or Rhel, there are three defined host names: A, static, B, transient (transient), and C, flexible (pretty). The "Static" hostname, also known as the kernel hostname, is the host name that the system automatically initializes from/etc/hostname at startup. A "transient" hostname is a host name that is temporarily assigned when the system is running, for example, through DHCP or MDNs server assignment. The static hostname and transient host name comply with the same character restriction rules as the Internet domain name. On the other hand, the "flexible" hostname allows the use of a host name of free form (including special/whitespace characters) to be displayed to the end user (such as Dan's computer).

In Centos/rhel 7, there is a command-line tool called Hostnamectl, which allows you to view or modify the configuration associated with a host name.

To view the host name-related settings:

$ HOSTNAMECTL Status

View only static, transient, or flexible hostname, using "--static", "--transient" or "--pretty" options, respectively.

$ hostnamectl Status [--static|--transient|--pretty]

To modify all three host names at the same time: static, transient, and flexible hostname:

$ sudo hostnamectl set-hostname 

As shown above, when modifying a static/transient hostname, any special characters or whitespace characters are removed, and any uppercase letters in the supplied parameters are automatically converted to lowercase. Once the static hostname has been modified,/etc/hostname will be automatically updated. However,/etc/hosts does not update to save the changes, so you need to manually update the/etc/hosts.

If you only want to modify a specific hostname (static, transient or flexible), you can use the "--static", "--transient" or "--pretty" option.

For example, to permanently modify a host name, you can modify the static hostname:

$ sudo hostnamectl--static set-hostname 

Note that you do not have to restart the machine to activate the permanent hostname modification. The command above immediately modifies the kernel hostname. Log out and re-login to observe the new static hostname at the command prompt.


CentOS 7 Modify hostname

Related Article

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.