你可以使用以下的任何工具来管理CentOS Linux7的hostnames:
- hostnamectl command : 控制系统的hostname,推荐使用这个。
- nmtui command : 使用文本用户接口(text user interface (TUI))来控制系统的hostname.
- nmcli command : 使用网络管理(NetworkManager)的CLI部分来控制系统的hostname.
hostnames的种类
hostname可以配置为以下几种:
1. Static hostname: 由sysadmin分配. 例如 “server1”, “wwwbox2”, or server42.cyberciti.biz.
2. Transient/dynamic hostname: 由DHCP 或 mDNS server在运行时分配.
3. Pretty hostname: 由sysadmin/end-users分配,并且它是自由形态的UTF8 hostname,用了呈现给用户。例如 “Vivek’s netbook”.
方法1: 使用hostnamectl命令
如何显示现在的hostname设置情况
使用命令hostnamectl 或者 hostnamectl status
$ hostnamectl
结果
Static hostname: Auto.redhat72.qatest.talend.lan
Icon name: computer-vm
Chassis: vm
Machine ID: 892b6f5b25594ad9b72c89cee1723abf
Boot ID: 9e399a2bcc1f4a2fb615aed2dce513d3
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
$ hostnamectl status
结果
Static hostname: Auto.redhat72.qatest.talend.lan
Icon name: computer-vm
Chassis: vm
Machine ID: 892b6f5b25594ad9b72c89cee1723abf
Boot ID: 9e399a2bcc1f4a2fb615aed2dce513d3
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
如何设置hostname
# hostnamectl set-hostname Your-New-Host-Name-Here
# hostnamectl set-hostname "Your New Host Name Here" --pretty
# hostnamectl set-hostname Your-New-Host-Name-Here --static
# hostnamectl set-hostname Your-New-Host-Name-Here --transient
如何删除某个hostname
# hostnamectl set-hostname ""
# hostnamectl set-hostname "" --static
# hostnamectl set-hostname "" --pretty
如何远程设置hostname
# ssh root@server-ip-here hostnamectl set-hostname server1
或者
# hostnamectl set-hostname server1 -H root@192.168.1.42
别的办法就不翻译了,有兴趣请参考
http://www.cyberciti.biz/faq/rhel-redhat-centos-7-change-hostname-command/