centos 7快速设置主机名指令hostnamectl介绍
hostnamectl指令是在centos7中增加的一个,我们可以利用它来设置主机名,下面来看个简单的例子.
centos7 上在主机名变更新增了一个hostnamectl 指令,该指令的无论在输出和更改上都较之前更加的便利,先看下hostname的help帮助信息,代码如下:
- [root@361way~]#hostnamectl--help
- hostnamectl[OPTIONS...]COMMAND...
- Queryorchangesystemhostname.
- -h--helpShowthishelp
- --versionShowpackageversion
- --transientOnlysettransienthostname
- --staticOnlysetstatichostname
- --prettyOnlysetprettyhostname
- -P--privilegedAcquireprivilegesbeforeexecution
- --no-ask-passwordDonotpromptforpassword
- -H--host=[USER@]HOSTOperateonremotehost
- Commands:
- statusShowcurrenthostnamesettings
- set-hostnameNAMESetsystemhostname
- set-icon-nameNAMESeticonnameforhost
- set-chassisNAMESetchassistypeforhost
查看hostname信息,代码如下:
- [root@361way~]#hostnamectl
- Statichostname:361way
- Iconname:computer-desktop
- Chassis:desktop
- MachineID:6917731f5fe447d0bca296ed2802e250
- BootID:e0d20bc2a3a4474c960394967d33ab53
- OperatingSystem:CentOSLinux7(Core)
- CPEOSName:cpe:/o:centos:centos:7
- Kernel:Linux3.10.0-123.6.3.el7.x86_64
- Architecture:x86_64
设置主机名,从上面的help 帮助里可以看到,在设置主机名时,这里涉及到四种主机名,在hostnamectl 的man手册里给予了说明和解释,代码如下:
- Thistooldistinguishesthreedifferenthostnames:thehigh-level"pretty"hostnamewhichmightincludeallkindsofspecialcharacters(e.g."Lennart's
- Laptop"),thestatichostnamewhichisusedtoinitializethekernelhostnameatboot(e.g."lennarts-laptop"),andthetransienthostnamewhichmightbe
- assignedtemporarilyduetonetworkconfigurationandmightrevertbacktothestatichostnameifnetworkconnectivityislostandisonlytemporarily
- writtentothekernelhostname(e.g."dhcp-47-11").
- Notethattheprettyhostnamehaslittlerestrictionsonthecharactersused,whilethestaticandtransienthostnamesarelimitedtotheusuallyaccepted //phpfensi.com
- charactersofInternetdomainnames.
更改主机名,一般情况下都是使用set-hostname进行更改,代码如下:
[root@361way ~]# hostnamectl set-hostname blog
更改主机名一般会涉及到/etc/hostname 、/etc/machine-info 两个文件,同时对于不同的名字修改在man手册上也给了说明:
The static hostname is stored in /etc/hostname, see hostname(5) for more information. The pretty hostname, chassis type, and icon name are stored in /etc/machine-info, see machine-id(5).
set-icon-name 设置的主机一般和图形界面会用到,对应的hostnamectl 输出中的Icon name,set-chassis 指定了主机的平台类型,如本机的是desktop,还可以设置为:"desktop","laptop","server","tablet","handset".
热门评论