Hostname / Host ID
Commands
cat /proc/sys/kernel/hostname
Hostname directly from the kernel's hostname file.
hostname
Displays the hostname.
uname -n
Displays just the hostname.
hostnamectl
*systemd systems - Most comprehensive hostname info
cat /etc/hostname
Displays the hostname stored in the /etc/hostname file.
hostid
Prints the numeric identifier for the current host.
Multiple hostnames: A system can have different hostnames configured for various purposes.
Static vs. Transient
hostnamectl
distinguishes between static (set in configuration files) and transient (set at runtime) hostnames.
File Locations
/etc/hostname
On many Linux distributions such as Debian and Ubuntu, stores the system's hostname.
/etc/hosts
Contains mappings of IP addresses to hostnames, often includes the system's hostname for the loopback interface.
/etc/sysconfig/network
On Red Hat-based distributions like Red Hat Enterprise Linux (RHEL) and CentOS, sets the system's hostname.
/etc/rc.conf or /etc/rc.conf.local
On some Unix systems like FreeBSD, stores the hostname information.
Dynamic Host Configuration Protocol
In network configurations using DHCP, the hostname may be assigned dynamically by the DHCP server.
hostname command
Used to view or change the hostname temporarily during a session.
Network Configuration Files
Some Unix distributions store hostname information in network configuration files.
NIS/NIS+
In network environments using NIS or NIS+ for centralized authentication and configuration management.
Last updated
Was this helpful?