Linux

Where Is the Hostname Stored on Linux?

/etc/hostname and /etc/hosts on Linux: where the machine name lives and how to change it.

Last updated

The static hostname lives in /etc/hostname as a single line, with local resolution mappings in /etc/hosts. Most tools read these at startup.

Editing by hand works, but hostnamectl keeps the file, kernel name and dependent services consistent in one step.

Where Linux stores this, by platform

Linux
/etc/hostname

Single-line static hostname. Prefer hostnamectl set-hostname over hand edits. Keep /etc/hosts loopback entries in sync.

Frequently asked questions

How do I change the Linux hostname?

Set it with hostnamectl set-hostname, which updates /etc/hostname and the live name together. Also update /etc/hosts 127.0.1.1 line to match, or sudo will warn about unresolvable hosts.

Notice an outdated path? Let us know.