Hostnamectl: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | |||
* http://man7.org/linux/man-pages/man1/hostnamectl.1.html | |||
* http://man7.org/linux/man-pages/man8/systemd-hostnamed.8.html | |||
=Internal= | =Internal= | ||
* [[Linux#Commands|Linux]] | * [[Linux#Commands|Linux]] | ||
* [[Linux Hostname]] | * [[Linux Hostname]] | ||
* [[hostname|<tt>hostname</tt> command]] | |||
* [[systemd-hostnamed]] | |||
=Overview= | =Overview= | ||
<tt>hostnamectl</tt> is the recommended tool to administer the three separate classes of host names ([[Linux Hostname#static_hostname|static]], [[Linux Hostname#pretty_hostname|pretty]] and [[Linux Hostname#transient_hostname|transient]]) in use on a given system. | |||
=Displaying Hostname Information= | |||
<pre> | |||
hostnamectl status | |||
Static hostname: docker-server.local | |||
Icon name: computer-vm | |||
Chassis: vm | |||
Machine ID: 265bdd8b7fe74f8db5fa674d8afde0c2 | |||
Boot ID: e862ea344dd24bcfa7c398039a0a9493 | |||
Virtualization: kvm | |||
Operating System: CentOS Linux 7 (Core) | |||
CPE OS Name: cpe:/o:centos:centos:7 | |||
Kernel: Linux 3.10.0-514.10.2.el7.x86_64 | |||
Architecture: x86-64 | |||
</pre> | |||
=Change the Host Name= | |||
The preferred way to change a host name is with <tt>hostnamectl</tt> as follows: | |||
<pre> | |||
hostnamectl set-hostname <name> | |||
</pre> | |||
Example: | |||
<pre> | |||
hostnamectl set-hostname docker-server.local | |||
</pre> | |||
This commands changes all the hostnames ([[Linux Hostname#static_hostname|static]], [[Linux Hostname#pretty_hostname|pretty]] and [[Linux Hostname#transient_hostname|transient]]) of the system. For more details on host names and recommended naming conventions, see {{Internal|Linux Hostname#Overview|Linux Host Names}} | |||
==hostnamectl set-hostname and /etc/hosts== | |||
{{Warn|Note that changing the host name with <tt>hostnamectl set-hostname</tt> does not update <tt>/etc/hosts</tt> so you may want to review <tt>/etc/hosts</tt> and change the mapping of the host's network interface addresses to the new name.}} | |||
==If the Name is Publicly Resolved by DNS== | |||
<font color=red>TODO http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html</font> | |||
==/etc/sysconfig/network HOSTNAME== | |||
Setting HOSTNAME in <tt>/etc/sysconfig/network</tt> as shown in the following example | |||
<pre> | |||
... | |||
NETWORKING=yes | |||
GATEWAY=192.168.0.1 | |||
... | |||
HOSTNAME=not500.localdomain | |||
</pre> | |||
may interfere with network configuration script and change the host name. | |||
{{Warn|This is '''NOT''' the preferred way of changing the host name, <tt>hostnamectl</tt> is.}} | |||
=Setting a Particular Host Name= | |||
<pre> | |||
hostnamectl [--static|--pretty|--transient] set-hostname <name> | |||
</pre> |
Latest revision as of 02:49, 4 April 2017
External
- http://man7.org/linux/man-pages/man1/hostnamectl.1.html
- http://man7.org/linux/man-pages/man8/systemd-hostnamed.8.html
Internal
Overview
hostnamectl is the recommended tool to administer the three separate classes of host names (static, pretty and transient) in use on a given system.
Displaying Hostname Information
hostnamectl status Static hostname: docker-server.local Icon name: computer-vm Chassis: vm Machine ID: 265bdd8b7fe74f8db5fa674d8afde0c2 Boot ID: e862ea344dd24bcfa7c398039a0a9493 Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-514.10.2.el7.x86_64 Architecture: x86-64
Change the Host Name
The preferred way to change a host name is with hostnamectl as follows:
hostnamectl set-hostname <name>
Example:
hostnamectl set-hostname docker-server.local
This commands changes all the hostnames (static, pretty and transient) of the system. For more details on host names and recommended naming conventions, see
hostnamectl set-hostname and /etc/hosts
Note that changing the host name with hostnamectl set-hostname does not update /etc/hosts so you may want to review /etc/hosts and change the mapping of the host's network interface addresses to the new name.
If the Name is Publicly Resolved by DNS
TODO http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html
/etc/sysconfig/network HOSTNAME
Setting HOSTNAME in /etc/sysconfig/network as shown in the following example
... NETWORKING=yes GATEWAY=192.168.0.1 ... HOSTNAME=not500.localdomain
may interfere with network configuration script and change the host name.
This is NOT the preferred way of changing the host name, hostnamectl is.
Setting a Particular Host Name
hostnamectl [--static|--pretty|--transient] set-hostname <name>