2024年4月18日发(作者:)

安装好虚拟机后进入终端时是:[root@localhost ~]#

也就是主机名为:localhost

那么如何改成自己想要的主机名呢

1.修改/etc/host内容

未修改前状态是:

[root@localhost ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1 omain localhost

[root@localhost ~]#

在末尾加上自己想要的主机名和ip地址(用ifconfig命令即可看到本机的ip地址了):

用vi /etc/hosts命令修改hosts文件的内容,修改后如下:

[root@localhost ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1 omain localhost

192.168.211.130 life

[root@localhost ~]#

2.修改/etc/sysconfig/network文件:

修改前如下:

[root@localhost ~]# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=omain

[root@localhost ~]#