centos中修改主机名的规范
修改主机名的规范步骤:
第一步:hostname 主机名
举例:把主机名oldboy修改成oldboylinux
[root@oldboy ~]# hostname
oldboy
[root@oldboy ~]# hostname oldboylinux
[root@oldboy ~]# hostname
oldboylinux
第二步:/etc/sysconfig/network 中的HOSTNAME也要修改成oldboylinux
此操作是针对于全局有效的。
[root@oldboylinux ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=oldboy
[root@oldboylinux ~]# sed -i 's#oldboy#oldboylinux#g' /etc/sysconfig/network
[root@oldboylinux ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=oldboylinux
[root@oldboylinux ~]# /etc/sysconfig/networkHOSTNAME
第三步:本地hosts回环主机名也要修改
[root@oldboylinux ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 oldboy
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 oldboy
[root@oldboylinux ~]# sed -i 's#oldboy#oldboylinux#g' /etc/hosts
[root@oldboylinux ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 oldboylinux
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 oldboylinux
补充说明:如果用setup--dns设置主机名,永久生效(但命令行不生效,不推荐此方法)
影响/etc/sysconfig/network和/etc/hosts配置文件