mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
Translate:20140915 Linux FAQs with Answers--How to change hostname on CentOS or RHEL 7.md
This commit is contained in:
parent
9450271192
commit
1152ae17aa
@ -1,43 +0,0 @@
|
||||
Translating by GOLinux ...
|
||||
Linux FAQs with Answers--How to change hostname on CentOS or RHEL 7
|
||||
================================================================================
|
||||
> Question: What is a proper way to change hostname on CentOS / RHEL 7 (permanently or temporarily)?
|
||||
|
||||
In CentOS or RHEL, there are three kinds of hostnames defined: (1) static, (2) transient, and (3) pretty. The "static" hostname is also known as kernel hostname, which is initialized from /etc/hostname automatically at boot time. The "transient" hostname is a temporary hostname assigned at run time, for example, by a DHCP or mDNS server. Both static and transient hostnames follow the same character restriction rules as Internet domain names. On the other hand, the "pretty" hostname is allowed to have a free-form (including special/whitespace characters) hostname, presented to end users (e.g., Dan's Computer).
|
||||
|
||||
In CentOS/RHEL 7, there is a command line utility called hostnamectl, which allows you to view or modify hostname related configurations.
|
||||
|
||||
To view hostname related settings:
|
||||
|
||||
$ hostnamectl status
|
||||
|
||||
![](https://farm4.staticflickr.com/3844/15113861225_e0e19783a7.jpg)
|
||||
|
||||
To view static, transient or pretty hostname only, use "--static", "--transient" or "--pretty" option, respectively.
|
||||
|
||||
$ hostnamectl status [--static|--transient|--pretty]
|
||||
|
||||
To change all three hostnames: static, transient, and pretty, simultaneously:
|
||||
|
||||
$ sudo hostnamectl set-hostname <host-name>
|
||||
|
||||
![](https://farm4.staticflickr.com/3855/15113489172_4e25ac87fa_z.jpg)
|
||||
|
||||
As shown above, in case of static/transient hostnames, any special or whitespace character will be removed, and any uppercase letter will automatically be converted to lowercase in the supplied <host-name> argument. Once the static hostname is changed, /etc/hostname will automatically be updated accordingly. However, /etc/hosts will not be updated to reflect the change, so you need to update /etc/hosts manually.
|
||||
|
||||
If you want to change a particular hostname only (static, transient or pretty), you can use "--static", "--transient" or "--pretty" option.
|
||||
|
||||
For example, to change hostname permanently, you can change the static hostname:
|
||||
|
||||
$ sudo hostnamectl --static set-hostname <host-name>
|
||||
|
||||
Note that you do not have to reboot the machine to activate permanent hostname change. The above command will change kernel hostname immediately. Log out, and log back in to see the new static hostname in the command-line prompt.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/change-hostname-centos-rhel-7.html
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -0,0 +1,42 @@
|
||||
Linux有问必答——如何在CentOS或RHEL 7上修改主机名
|
||||
================================================================================
|
||||
> 问题:在CentOS/RHEL 7上修改主机名的正确方法是什么(永久或临时)?
|
||||
|
||||
在CentOS或RHEL中,有三种定义的主机名:(1)静态的,(2)瞬态的,以及(3)优雅的。“静态”主机名也成为内核主机名,是系统在启动时从/etc/hostname自动初始化的主机名。“瞬态”主机名是在系统运行时临时分配的主机名,例如,通过DHCP或mDNS服务器分配。静态主机名和瞬态主机名都遵从作为互联网域名同样的字符限制规则。而另一方面,“优雅”主机名则被允许使用自由形式(包括特殊/空白字符)的主机名,以展示给终端用户(如Dan's Computer)。
|
||||
|
||||
在CentOS/RHEL 7中,有个叫hostnamectl的命令行工具,它允许你查看或修改与主机名相关的配置。
|
||||
|
||||
要查看主机名相关的设置:
|
||||
|
||||
$ hostnamectl status
|
||||
|
||||
![](https://farm4.staticflickr.com/3844/15113861225_e0e19783a7.jpg)
|
||||
|
||||
只查看静态、瞬态或优雅主机名,分别使用“--static”,“--transient”或“--pretty”选项。
|
||||
|
||||
$ hostnamectl status [--static|--transient|--pretty]
|
||||
|
||||
要同时修改所有三个主机名:静态、瞬态和优雅主机名:
|
||||
|
||||
$ sudo hostnamectl set-hostname <host-name>
|
||||
|
||||
![](https://farm4.staticflickr.com/3855/15113489172_4e25ac87fa_z.jpg)
|
||||
|
||||
就像上面展示的那样,在修改静态/瞬态主机名时,任何特殊字符或空白字符会被移除,而提供的参数中的任何大写字母会自动转化为小写。一旦修改了静态主机名,/etc/hostname将被自动更新。然而,/etc/hosts不会更新以对修改作出回应,所以你需要手动更新/etc/hosts。
|
||||
|
||||
如果你只想修改特定的主机名(静态,瞬态或优雅),你可以使用“--static”,“--transient”或“--pretty”选项。
|
||||
|
||||
例如,要永久修改主机名,你可以修改静态主机名:
|
||||
|
||||
$ sudo hostnamectl --static set-hostname <host-name>
|
||||
|
||||
注意,你不必重启机器以激活永久主机名修改。上面的命令会立即修改内核主机名。注销并重新登入后在命令行提示观察新的静态主机名。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/change-hostname-centos-rhel-7.html
|
||||
|
||||
译者:[GOLinux](https://github.com/GOLinux)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user