Host name is used to identify the systems like hosts, clients, servers etc. Host name provides human readable easy names to remember. In a big environment host names will provides some easy of use. This tutorial is compatible with RHEL6, RHEL7, Fedora, CentOS 6 and CentOS 7 versions
主机名用于标识主机,客户端,服务器等系统。主机名提供了易于阅读的易于记忆的名称。 在大型环境中,主机名将提供一些易于使用的名称。 本教程与RHEL6,RHEL7,Fedora,CentOS 6和CentOS 7版本兼容
主机名如何工作(How Host Names Works)
In basic form computer networks like TCP/IP works with IP addresses to communicate. IP addresses are not practical for remember and usage. So we name hosts with host names where these host names are associated with related IP address. In the following example we associate host name web1
with IP address 192.168.122.10
在基本形式中,像TCP / IP这样的计算机网络都可以与IP地址进行通信。 IP地址不便于记忆和使用。 因此,我们用主机名来命名主机,这些主机名与相关的IP地址相关联。 在以下示例中,我们将主机名web1
与IP地址192.168.122.10
关联
192.168.122.10 web1
For more detailed host naming with fully qualified domain name read following tutorials.
有关使用完全限定域名的更详细的主机命名的信息,请阅读以下教程。
What is FQDN (Fully Qualified Domain Name) with Examples?
更改网络配置文件中的主机名 (Change Host Name In Network Config File)
One way to change CentOS server host name is editing the network config file. CentOS network config file resides in /etc/sysconfig/network
. We will open this file with out favourite editor which is vi
in this example. Also we need root privileges in order to edit and save network config file.
更改CentOS服务器主机名的一种方法是编辑网络配置文件。 CentOS网络配置文件位于/etc/sysconfig/network
。 我们将使用不喜欢的编辑器(在此示例中为vi
打开此文件。 另外,我们需要root特权才能编辑和保存网络配置文件。
$ vi /etc/sysconfig/network
and we will add following line or change if it exists. In this example we will set HOSTNAME
configuration to poftut3
我们将添加以下行或进行更改(如果存在)。 在此示例中,我们将HOSTNAME
配置设置为poftut3
HOSTNAME=poftut3
In order to apply new host name we need to restart network services with the following command.
为了应用新的主机名,我们需要使用以下命令重新启动网络服务。
$ systemctl restart network
使用hostname命令更改主机名 (Change Host Name with hostname Command)
We have all ready examined the hostname
command which is used to change and set hostname of fully qualified domain name. We can simply specify the new host name after hostname
command. In this example we will set host name as poftut5
. This will require root privileges
我们已经准备好检查hostname
命令,该命令用于更改和设置标准域名的主机名。 我们可以在hostname
命令之后简单地指定新的主机名。 在此示例中,我们将主机名设置为poftut5
。 这将需要root特权
$ hostname poftut5
将主机名和关联的IP地址添加到主机文件(Add Host Name and Associated IP Address To Hosts File)
After changing CentOS host name we should also set new host name and IP address associated in the local system and other systems. We will add host name and IP address to the /etc/hosts
file like below. This will also require root privileges too.
更改CentOS主机名后,我们还应该设置本地系统和其他系统中关联的新主机名和IP地址。 我们将主机名和IP地址添加到/etc/hosts
文件中,如下所示。 这也将需要root特权。
192.168.122.10 poftut3
翻译自: https://www.poftut.com/change-centos-server-host-hostname/