更改linux的主机名为server03

系统:

[root@localhost ~]# cat /etc/issue
Red Hat Enterprise Linux Server release 6.8 (Santiago)
Kernel \r on an \m

修改办法

1:修改/etc/sysconfig/network  中的localhost.localdomain

[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
[root@localhost ~]# sed -i 's/'localhost.localdomain'/'server03'/g' /etc/sysconfig/network
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=server03

 

2:修改 /etc/hosts

[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

 

修改第一行的 localhost.localdomain  为要改的主机名 server03

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

127.0.0.1   localhost server03 localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost server03 localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

3:重启linux   

[root@localhost ~]# reboot

执行hostname查看修改后的主机名

[root@server03 ~]# hostname
server03

 

 

 

你可能感兴趣的:(Linux)