Change a server’s hostname in CentOS

Using a text editor, open the server’s /etc/sysconfig/network file. The following example shows how to open this file in the GNU nano text editor:

vi /etc/sysconfig/network

Modify the HOSTNAME= value to match your FQDN hostname, as shown in the following example:

HOSTNAME=myserver.domain.com

Open the file at /etc/hosts. To update the information for internal networking, change the host that is associated with the main IP address for your server, as shown in the following example:

127.0.0.1 localhost localhost.localdomain

123.45.67.89 hostname.domain.com hostname

Run the hostname command. This command enables you to change the hostname on the server that the command line remembers, but it does not actively update all of the programs that are running under the old hostname. The following code provides an example:

[root@ ~]# hostnamectl set-hostname hostname.domain.com

[root@ ~]# hostname hostname.domain.com

[root@~]#

Use the following command to restart networking on your server to ensure that changes persist on restart:

# /etc/init.d/network restart

Giới thiệu Liêm Phan 167 bài viết
Mình lập blog này với mục đích lưu lại + chia sẻ các các kiến thức mình đã biết hoặc đang tìm hiểu. Cơ bản giúp ích cho mình :) Nhưng hy vọng sẽ mang lại sự khởi đầu thuận lợi cho người mới bắt đầu!