如何更改CentOS服务器/主机的主机名?

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?

什么是带有示例的FQDN(完全合格域名)?

更改网络配置文件中的主机名 (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
Change Host Name In Network Config File
Change Host Name In Network Config File
更改网络配置文件中的主机名

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
Change Host Name with hostname Command
Change Host Name with hostname Command
使用hostname命令更改主机名

将主机名和关联的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
LEARN MORE  How To Restart CentOS, Fedora, RedHat?
了解更多如何重启CentOS,Fedora,RedHat?

翻译自: https://www.poftut.com/change-centos-server-host-hostname/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值