CentOS (6, 7) Modify host name (hostname)

Source: Internet
Author: User
Centos6

Two places need to be modified: One is/etc/sysconfig/network, the other is/etc/hosts, and modifying any one of these will cause the system to boot abnormally. First switch to root user.

/etc/sysconfig/network
Open the file, which has a line of ' Hostname=localhost.localdomain, modify localhost.localdomain for your host name.

/etc/hosts
Opening the file, there will be a row 127.0.0.1 localhost.localdomain localhost where 127.0.0.1 is the local loop address, Localhost.localdomain is the host name (hostname), Which is what you want to change.

When the above two documents have been modified, they will not take effect immediately. If you want to take effect immediately, you can use hostname your-hostname to make a temporary change (or, after modification, execute EXEC bash immediately changes), it only temporarily modifies the hostname, viewing the host name Uname-n the system reboot will return to the original.

However, modifying the top two files is permanent, and restarting the system will get the new host name.
Finally, check the host name uname-n after reboot. Centos7

Temporary entry into force

[ROOT@CENTOS7 ~]# hostname 132
[ROOT@CENTOS7 ~]# hostname
132

Permanent (not immediately modified, reboot required)

[Root@centos7 ~]# hostnamectl set-hostname centos7
(or perform ' EXEC bash ' immediately change after modification),
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.