Updated: 4 November 2026 · Applies to: hostname 3.23 to 3.25 on AlmaLinux 10.2, Debian 13, Ubuntu 24.04 and 26.04, and hostnamectl (systemd 257) on AlmaLinux 10.2, tested
To display the hostname in Linux, run hostname. It prints the name the kernel uses right now. hostname -f shows the fully qualified domain name (FQDN), hostname -I shows the server's IP addresses, and hostnamectl shows the hostname together with the operating system and kernel. The saved name is in /etc/hostname.
The lab examples below come from an AlmaLinux 10.2 test system named vps, with this line in /etc/hosts (addresses replaced with documentation addresses):
203.0.113.10 vps.example.com vps
1. Five ways to show the hostname
$ hostname vps $ uname -n vps $ cat /etc/hostname vps $ cat /proc/sys/kernel/hostname vps $ echo $HOSTNAME vps
hostname, uname -n and /proc/sys/kernel/hostname show the current (transient) name. /etc/hostname holds the static name that is set at boot. $HOSTNAME is a variable that bash sets for you.
2. hostname command examples
$ hostname -s # short name, cut at the first dot vps $ hostname -f # FQDN (also --fqdn or --long) vps.example.com $ hostname -d # DNS domain only example.com $ hostname -i # address(es) the host name resolves to 203.0.113.10 $ hostname -I # all addresses on all interfaces 203.0.113.10 $ hostname -A # all FQDNs, by reverse lookup of each address vps.example.com
-ionly works if the host name can be resolved;-Ilists the addresses of the network interfaces directly and is the better choice for "what is my server's IP". It shows local addresses only: behind NAT, the public address differs (see How to Find Your IP Address in Linux from the Command Line (Local, Public, Router and Hostname IP)).-aprints aliases from/etc/hosts; according to its manual page it is deprecated.-yanddomainnameshow the old NIS domain, not the DNS domain. Usehostname -dordnsdomainnameinstead.
Debian 13 (hostname 3.25), Ubuntu 24.04 (3.23) and Ubuntu 26.04 (3.25) all use the same hostname program with these options, so the examples apply there too.
3. hostnamectl: hostname plus system details
On systems with systemd, hostnamectl shows the static hostname and more. Lab example, shortened (the Machine ID, Boot ID, kernel and OS support lines are left out):
$ hostnamectl
Static hostname: vps
Icon name: computer-container
Chassis: container
Virtualization: podman
Operating System: AlmaLinux 10.2 (Lavender Lion)
Architecture: x86-64
To print one value only:
hostnamectl hostname # current hostname hostnamectl --static # name stored in /etc/hostname hostnamectl --transient # name the kernel uses now hostnamectl --pretty # free-text name, empty unless set
4. Where the FQDN comes from: /etc/hosts
hostname -f does not read /etc/hostname. It asks the resolver, which usually finds the answer in /etc/hosts. The full name must come first on the line, then the short name:
203.0.113.10 vps.example.com vps
In our test, the reversed order (203.0.113.10 vps vps.example.com) made hostname -f print just vps and hostname -d print nothing. With no line for the host at all, hostname -f printed the short name and hostname -i listed every local address, including an IPv6 link-local one, because AlmaLinux resolves its own name through systemd's myhostname module.
On Debian and Ubuntu, according to the Debian Reference manual, the installer adds a line like 127.0.1.1 hostname for systems without a permanent IP address; a server with a fixed IP should use that IP and the full name instead. A correct FQDN matters for mail servers and control panels; see Important: The hostname needs to be resolved.
5. Changing the hostname (and when it is not possible)
- Temporary, until the next reboot:
hostname vps2.example.com - Permanent, on systemd systems:
hostnamectl hostname vps2.example.com(systemd 249 and newer; older versions usehostnamectl set-hostname, which still works). This writes/etc/hostnameand changes the running name. - Update the line in
/etc/hostssohostname -freturns the new name.
According to the hostnamectl manual, a hostname can be at most 64 characters, and it should use 7-bit ASCII lower-case characters without spaces: a single label, or a valid DNS name such as vps.example.com. Step-by-step guides: How to Set or Change the Hostname in Linux With hostnamectl and How to Change the Hostname Permanently in Linux (Fedora, Rocky Linux, RHEL 9 and Ubuntu) and Set the Domain Name.
Containers: these changes need a real server or virtual machine. Inside a podman container, even as root, both failed:
$ hostname vps3 hostname: you must be root to change the host name $ hostnamectl hostname vps2.example.com Could not set static hostname: Failed to set static hostname: Device or resource busy
A container gets its hostname when it is created (--hostname in podman and Docker), and its /etc/hostname and /etc/hosts are managed by the container engine. Displaying the name works normally.
On a Ucartz KVM VPS you have full root access, so the commands above work. You can also change the VPS hostname from the Virtualizor panel: see How to Change Your VPS Hostname in Virtualizor.
Official documentation: hostname manual, hostnamectl manual and Debian Reference, network setup.