Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

How to Change a Hostname on Linux Without Rebooting Everything

Sean

Platform Writer

Jun 30, 2026
4 min read

Changing a Linux hostname is two commands with hostnamectl (no reboot required) or three edits without it (legacy approach, requires a reboot for the kernel-level change). The hostnamectl approach is the right one for any modern Linux distribution.

How to Change a Hostname on Linux Without Rebooting Everything

Table of contents

The hostnamectl approach

The right tool for any systemd-based distribution:

sudo hostnamectl set-hostname new-hostname.example.com

That’s it. The change is immediate; the running services see the new hostname on their next lookup. The team that wants to verify: hostnamectl (no arguments) shows the current hostname and the operating system.

The pretty hostname vs the static hostname

hostnamectl sets three things:

  • Static hostname: the kernel-level hostname, used by the system libraries.
  • Pretty hostname: the human-readable form (e.g., “web-prod-01”), used by desktop environments.
  • Transient hostname: set by DHCP or mDNS, used when the static hostname is not set.

set-hostname sets all three. The team that wants to set them separately uses --static, --pretty, or --transient.

The legacy approach (without hostnamectl)

For the team on a non-systemd distribution:

  1. Edit /etc/hostname with the new hostname.
  2. Edit /etc/hosts and update the line that maps 127.0.1.1 to the old hostname.
  3. Reboot.

Step 2 is the one the team forgets. Without it, the hostname resolves to the old name on the loopback, and some applications (sudo, ssh) log warnings.

What changes when the hostname changes

The five things that change:

  • hostname and hostname -f return the new value.
  • New log entries use the new hostname.
  • Some daemons (Postfix, nginx) need a reload to pick up the new hostname.
  • TLS certificates with the hostname in the CN may need to be regenerated.
  • SSH host keys are tied to the hostname; changing the hostname does not regenerate them but the team may want to.

The team that changes the hostname on a production server should reload the affected daemons.

What usually breaks

The four pitfalls:

  • Forgot /etc/hosts. The team that only edits /etc/hostname gets hostname returning the new name but hostname -f returning the old one.
  • Forgot to reload daemons. Postfix keeps logging the old hostname until it is reloaded.
  • Forgot the FQDN form. A hostname like web-prod-01 is fine for a private network; the public-facing server needs the FQDN (web-prod-01.example.com).
  • Invalid characters. Hostnames can have letters, digits, and hyphens. Underscores are not allowed in hostnames (even though some tools accept them).

The three hostname types in detail

The kernel exposes three hostname types, and they serve different purposes:

  • Static hostname. The traditional Unix hostname. Set at boot from /etc/hostname, persisted across reboots. Used by most system utilities.
  • Transient hostname. A kernel-managed dynamic hostname. DHCP can set it; mDNS can change it. The kernel falls back to this when the static hostname is unset.
  • Pretty hostname. A free-form UTF-8 string for human display. The team that wants the GUI to show “Production Web Server 01” uses the pretty hostname.

hostnamectl set-hostname sets all three to the same value. The team that wants them different uses --static, --pretty, or --transient flags.

Common use case: pretty hostname is human-readable (“web-prod-01”), static is machine-friendly (“web-prod-01.example.com”), transient stays whatever DHCP set.

Hostname in containers

The hostname behaves differently inside containers:

  • Docker. The container’s hostname is the container ID by default. Set with docker run --hostname web-prod-01 ....
  • Kubernetes. The pod’s hostname is the pod name by default. Set with spec.hostname in the pod spec.
  • systemd-nspawn. The container’s hostname is the machine ID by default. Set with --hostname=web-prod-01.

The team that runs services in containers sets the hostname explicitly; the auto-generated hostname (container ID, pod name) is useless for monitoring and logging.

FAQ

Does changing the hostname require a reboot?

No, with hostnamectl. Yes, with the legacy approach if you want the kernel-level hostname to update immediately.

How long can a hostname be?

64 characters per label, 255 characters total. The team that uses a 200-character hostname is using a hostname that some tools will truncate.

Can I use uppercase in a hostname?

RFC-compliant hostnames are case-insensitive. The convention is lowercase. The team that uses uppercase has some tools that don’t normalize correctly.

Can I use underscores in a hostname?

Technically no (RFC 1123). In practice, some tools (especially Linux) allow it. The team that uses underscores has trouble with Windows tools that strictly enforce the RFC.

What’s the maximum hostname length?

64 characters per label, 255 characters total. The team that uses a 200-character hostname has trouble with some tools that truncate.

Can I use Unicode in a hostname?

Yes, in the pretty hostname. The static hostname should be ASCII (letters, digits, hyphens). The team that uses Unicode in the static hostname has tools that don’t handle it well.

Does changing the hostname require restarting services?

Most services pick up the new hostname automatically. Some (Postfix, nginx) need a reload. The team that changes the hostname on a production server should reload the affected daemons.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#hostname#linux#hostnamectl#systemd#server