Basic Linux Tutorial: how to modify the host name on CentOS or RHEL 7

Source: Internet
Author: User

Basic Linux Tutorial: how to modify the host name on CentOS or RHEL 7

Q: What is the correct method for modifying the host name on CentOS/RHEL 7 (either permanently or temporarily )?

In CentOS or RHEL, there are three defined host names: a, static (static), B, transient (transient), and c, flexible (pretty ). The "static" host name is also called the kernel host name. It is the host name automatically initialized from/etc/hostname at startup. The "transient" host name is a temporary host name allocated during system operation, such as through DHCP or mDNS server. Both the static host name and the transient host name follow the same character restriction rules as the Internet domain name. On the other hand, "flexible" host names allow the use of free-form (including special/blank characters) host names to be displayed to end users (such as Dan's Computer ).

In CentOS/RHEL 7, a command line tool named hostnamectl allows you to view or modify host name-related configurations.

To view host name settings:

  1. $ Hostnamectl status

Only view static, transient, or flexible host names. Use the "-- static", "-- transient", or "-- pretty" Options respectively.

  1. $ Hostnamectl status [-- static | -- transient | -- pretty]

You need to modify all three host names at the same time: static, transient, and flexible host names:

  1. $ Sudo hostnamectl set-hostname

As shown above, when modifying static/transient host names, any special or blank characters are removed, and any uppercase letters in the provided parameters are automatically converted to lowercase letters. Once the static host name is modified,/etc/hostname will be automatically updated. However,/etc/hosts will not be updated to save the changes, so you need to manually update/etc/hosts.

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

For example, to permanently modify the host name, you can modify the static Host Name:

  1. $ Sudo hostnamectl -- staticset-hostname

Note that you do not have to restart the machine to activate permanent host name modification. The preceding command immediately modifies the kernel host name. After logging out and logging on again, you will be prompted on the command line to observe the new static host name.

Impact of host name modification on Oracle startup and shutdown on Linux

How to display and set host names in Linux

Linux host name change

Change the host name in Linux (Ubuntu + RedHat)

Steps for modifying the host name in Linux

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.