1,通过修改文件/etc/sysconfig/network eg:
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=Server34 ---->修改想要的名字
2,修改文件/etc/hosts
127001 localhost Server34 localhost4 localhost4localdomain4
::1 localhost localhostlocaldomain localhost6 localhost6localdomain6
3,reboot 既可修改原主机名。
(二)CentOS72修改主机名
CentOS72修改主机名相对于65版本又有所改进,不需要重启就可以直接修改,具体的方法有如下三种:
(1)修改配置文件/etc/hostname来进行修改
[root@localhost ~]# vim /etc/hostname server23[root@localhost ~]# systemctl restart systemd-hostnamedservice[root@localhost ~]# hostnameserver23
(2)通过nmtui修改主机名
[root@localhost ~]# nmtui ┌─────────────────┤ Set Hostname ├──────────────────┐ │ │ │ Hostname Server23________________________________ │ │ │ │ <Cancel> <OK> │ │ │ └───────────────────────────────────────────────────┘ [root@localhost ~]# hostnameServer23
(3) hostnamectl的命令行工具
123456789101112131415161718192021222324252627282930313233[root@localhost ~]# hostnamectl -helphostnamectl [OPTIONS] COMMAND Query or change system hostname -h --help Show this help --version Show package version --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --transient Only set transient hostname --static Only set static hostname --pretty Only set pretty hostnameCommands: status Show current hostname settings set-hostname NAME Set system hostname set-icon-name NAME Set icon name for host set-chassis NAME Set chassis type for host set-deployment NAME Set deployment environment for host set-location NAME Set location for host[root@localhost ~]# hostnamectl status Static hostname: Server23 Icon name: computer-vm Chassis: vm Machine ID: b832bc29266640fe83d7256d53840cdc Boot ID: 33590b06c20b45bab1e8e12fbf4986d2 Virtualization: microsoft Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3100-327el7x86_64 Architecture: x86-64[root@localhost ~]# hostnamectl set-hostname servers23[root@localhost ~]# hostnameservers23
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)