Linux Hostname: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=


* Understanding host names https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/ch-Configure_Host_Names.html#sec_Understanding_Host_Names
* http://man7.org/linux/man-pages/man1/hostname.1.html
* http://man7.org/linux/man-pages/man1/hostname.1.html


Line 11: Line 12:
There are three different hostnames:
There are three different hostnames:


* The high-level '''"pretty" hostname''' which might include special characters.
* <span id="pretty_hostname"></span>The high-level '''"pretty" hostname''' which might include special characters.
* The '''static hostname''' which is used to initialize the kernel <tt>hostname</tt> at boot.
* <span id="static_hostname"></span>The '''static hostname''' which is used to initialize the kernel <tt>hostname</tt> at boot. The static hostname is stored in <tt>/etc/hostname</tt>, see [https://www.freedesktop.org/software/systemd/man/hostname.html hostname(5)] for more information.  
* The '''transient hostname''' which might be assigned temporarily due to network configuration and might revert back to the static hostname if network connectivity is lost and is only temporarily written to the kernel hostname.
* <span id="transient_hostname"></span>The '''transient hostname''' is a dynamic hostname maintained by the kernel; the initial value is the static host name value. The transient hostname may be changed by DHCP or mDNS at runtime, but might revert back to the static hostname if network connectivity is lost and is only temporarily written to the kernel hostname.


The static and transient hostnames are limited to the usually accepted characters of Internet domain names.
The static and transient hostnames are limited to the usually accepted characters of Internet domain names.


The static hostname is stored in <tt>/etc/hostname</tt>, see [https://www.freedesktop.org/software/systemd/man/hostname.html hostname(5)] for more information.  
The pretty hostname, chassis type, and icon name are stored in <tt>/etc/machine-info</tt>.


The pretty hostname, chassis type, and icon name are stored in /etc/machine-info.
If the host name must be changed, to permanently set name, use <tt>[[hostnamectl]]</tt>.


The hostname can be set at runtime with at least two commands: <tt>[[hostname]]</tt> and <tt>[[hostnamectl]]</tt>. The <tt>[[hostname]]</tt> command shows or set the system's host name. Note that the name set is such a way is ephemeral - will disappear at reboot. There's also a daemon that reacts to network events and sets the hostname: <tt>systemd-hostnamed</tt>. To permanently set name, configure the appropriate file. See below.
The host name can be read with <tt>[[hostname]]</tt>. If <tt>[[hostname]]</tt> is used to change the host name, the name set is such a way is ephemeral - will disappear at reboot, so do not use it to change host names, use <tt>[[hostnamectl]]</tt> instead.
 
There's also a daemon that reacts to network events and sets the hostname: <tt>systemd-hostnamed</tt>.


=Host Name and the Domain Name=
=Host Name and the Domain Name=
Line 27: Line 30:
When a machine is initially configured, the installation program usually suggest a fully qualified host name that usually has a host name component and a domain name component.
When a machine is initially configured, the installation program usually suggest a fully qualified host name that usually has a host name component and a domain name component.


<font color=red>Finish this.</font>
<font color=red>Finish this, link with [[DNS_Concepts#Host_Name_and_the_Domain_Name]].</font>


=Getting the Hostname=
=Getting the Hostname=


Display the hostname:
Display the hostname information:
 
<pre>
hostnamectl status
</pre>


<pre>
<pre>
Line 51: Line 58:
=<tt>/etc/hostname</tt>=
=<tt>/etc/hostname</tt>=


The <tt>/etc/hostname</tt> file configures the name of the local system that is set during boot using the <tt>sethostname(2)</tt> system call. It should contain a single newline-terminated hostname string. Depending on the operating system, other configuration files might be checked for configuration of the hostname as well, however only as fallback.
The <tt>/etc/hostname</tt> file configures the name of the local system that is set during boot using the <tt>sethostname(2)</tt> system call. It should contain a single newline-terminated hostname string. Depending on the operating system, other configuration files might be checked for configuration of the hostname as well, however only as fallback. You may use <tt>[[hostnamectl]]</tt> to change the value of this file from the command line. Also see [[Systemd-hostnamed#.2Fetc.2Fhostname|<tt>systemd-hostnamed</tt> <tt>/etc/hostname</tt>]].
 
You may use <tt>[[hostnamectl]]</tt> to change the value of this file from the command line. Also see [[Systemd-hostnamed#.2Fetc.2Fhostname|<tt>systemd-hostnamed</tt> <tt>/etc/hostname</tt>]].


=<tt>/proc/sys/kernel/hostname</tt>=
=<tt>/proc/sys/kernel/hostname</tt>=
Line 63: Line 68:
=cloud-init and hostname=
=cloud-init and hostname=


could-init may interfere with setting hostname at boot. For more details see [[cloud-init#SettingHostname]]
could-init may interfere with setting hostname at boot. For more details see [[Cloud-init#Setting_hostname|<tt>cloud-init</tt> - Setting hostname]].
 


=Configuration=
=Changing the Host Name=


<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
{{Internal|Hostnamectl#Change_the_Host_Name|Changing the Host Name with hostnamectl}}
:[[Linux 7 Configuring the Machine Name|Configuring the Machine Name]]
</blockquote>

Latest revision as of 02:44, 4 April 2017

External

Internal

Overview

There are three different hostnames:

  • The high-level "pretty" hostname which might include special characters.
  • The static hostname which is used to initialize the kernel hostname at boot. The static hostname is stored in /etc/hostname, see hostname(5) for more information.
  • The transient hostname is a dynamic hostname maintained by the kernel; the initial value is the static host name value. The transient hostname may be changed by DHCP or mDNS at runtime, but might revert back to the static hostname if network connectivity is lost and is only temporarily written to the kernel hostname.

The static and transient hostnames are limited to the usually accepted characters of Internet domain names.

The pretty hostname, chassis type, and icon name are stored in /etc/machine-info.

If the host name must be changed, to permanently set name, use hostnamectl.

The host name can be read with hostname. If hostname is used to change the host name, the name set is such a way is ephemeral - will disappear at reboot, so do not use it to change host names, use hostnamectl instead.

There's also a daemon that reacts to network events and sets the hostname: systemd-hostnamed.

Host Name and the Domain Name

When a machine is initially configured, the installation program usually suggest a fully qualified host name that usually has a host name component and a domain name component.

Finish this, link with DNS_Concepts#Host_Name_and_the_Domain_Name.

Getting the Hostname

Display the hostname information:

hostnamectl status
hostname

Display the fully qualified domain name (the long host name):

hostname -f

Display the DNS domain:

hostname -d

/etc/hostname

The /etc/hostname file configures the name of the local system that is set during boot using the sethostname(2) system call. It should contain a single newline-terminated hostname string. Depending on the operating system, other configuration files might be checked for configuration of the hostname as well, however only as fallback. You may use hostnamectl to change the value of this file from the command line. Also see systemd-hostnamed /etc/hostname.

/proc/sys/kernel/hostname

cat /proc/sys/kernel/hostname

cloud-init and hostname

could-init may interfere with setting hostname at boot. For more details see cloud-init - Setting hostname.

Changing the Host Name

Changing the Host Name with hostnamectl