CentOS7.0 modify host name (hostname)

Source: Internet
Author: User
Hostname in Linux is very important in most applications. for example, some applications force the host name instead of the IP address. if the default host name is localhost. if localdomain is used, the problem will occur, and it seems so unsatisfactory. In CentOS6 and earlier versions, you can modify the host name by modifying the configuration file. this configuration file is generally/etc/sysconfig/network. However, in CentOS7, many system management tools are

Hostname in Linux is very important in most applications. for example, some applications force the host name instead of the IP address. if the default host name is localhost. if localdomain is used, the problem will occur, and it seems so unsatisfactory. In CentOS6 and earlier versions, you can modify the host name by modifying the configuration file. this configuration file is generally/etc/sysconfig/network, but in CentOS7, many system management tools have been replaced.
 

For example, if you want to change the host name, you cannot refer to the previous method. the new configuration file has been updated to/etc/hostname, although modifying the/etc/sysconfig/network configuration file (this file still exists, but it is empty) may take effect, however, you have to consider whether some Linux software uses the source file or the environment variable $ HOSTNAME.
 

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 ). Therefore, you can modify the CentOS7 host name in the following ways.

 

0. set the host name when installing the operating system.


1. directly use the text editor to modify the/etc/hostname configuration file.


2. run the hostnamectl command, hostnamectl set-hostnameNameAnd then run the hostname or hostnamectl status command to check whether the change has taken effect.

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:

# hostnamectl status

 

Only view static, transient, or flexible host names. use the "-- static", "-- transient", or "-- pretty" options respectively.

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

Note *: the modified host name with any special or blank characters will be removed, and any uppercase letters in the provided parameters will be automatically converted to lowercase letters.

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.

 

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

# hostnamectl set-hostname 
 

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:

# hostnamectl --static set-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.

 

3. use nmcli general hostnameMy-serverCommand change.

For more information, see section 2nd and section 3.3 of Red Hat Enterprise Linux 7 Networking Guide.

For more information, see the man manual related to hostname. Systemd (1), hostname (1), hostname (5), machine-info (5), hostnamectl (1), sethostname (2)

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.