Hostname

// archive From the original Code Walker docs. Kept for reference, so some versions and commands may be out of date.

The hostname command displays or temporarily modifies the system’s fully qualified hostname.

hostname

Specify a static hostname in the /etc/hostname file. Use the hostnamectl command to modify this file and may be used to view the status of the system’s fully qualified hostname.

hostnamectl set-hostname host.example.com
hostnamectl status
cat /etc/hostname

The conversion of hostnames to IP addresses or the reverse is determined by the configuration of the /etc/nsswitch.conf file. By default, the contents of the /etc/hosts file is checked first.

If an entry isn’t found in the /etc/hosts file, the stub resolver tries to look up the hostname by using a DNS nameserver. /etc/resolv.conf file controls how this query is performed.

To test name resolution:

host server.exaple.com
host 192.168.122.100

Summary

The system’s static hostname is stored in the /etc/hostname file. Use the hostnamectl command to modify or view the status of the system’s hostname and related settings. The hostname command displays or temporarily modifies the system’s hostname.

Command References:

nmcli, hostnamectl, hosts, getent, host, nsswitch.conf and resolv.conf.