Amazon Cyber Monday deals See deals →ad

Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

Alpine Linux Change Hostname: Temporary and Permanent

To change the hostname in Alpine Linux permanently, edit /etc/hostname and put the new name on its own line, then reboot or apply it with hostname. For an immediate change in the current session, run sudo hostname new-name as root, or run hostname new-name directly when already logged in as root.

What the hostname does in Alpine

A hostname is the system’s local network identity: it helps users and services distinguish one machine from another. It may appear in the shell prompt, logs, monitoring tools, and network connections. Changing it does not rename a Linux user account, alter the machine’s IP address, or automatically update DNS records, router settings, or cloud inventory.

Alpine is a small, musl-based Linux distribution that commonly uses OpenRC rather than systemd. That difference matters in instructions: systemd commands such as hostnamectl are generally not the standard way to configure the hostname on a typical Alpine installation. Alpine’s basic persistent setting is stored in /etc/hostname.

Change the hostname immediately

To set the hostname until the next boot, use the hostname command. For example, to set it to edge-node-02:

hostname edge-node-02

Run the command as root. If your installation has sudo configured, you can instead use:

sudo hostname edge-node-02

Check the active value with:

hostname

This runtime change is useful for a quick test, but it is not a substitute for changing the saved configuration. On reboot, Alpine can restore the name from /etc/hostname, so a temporary change may disappear.

Set a permanent hostname

Edit /etc/hostname as root and replace its contents with the desired hostname. For example:

vi /etc/hostname

Enter a single line such as edge-node-02, save the file, and exit. The file should contain the hostname itself, not a command or a HOSTNAME= assignment. You can inspect it with:

cat /etc/hostname

To use the new name without rebooting, set the runtime hostname as well:

hostname edge-node-02

Some Alpine setups apply the saved name during startup; editing the file alone does not necessarily change the name of an already-running system. Rebooting is the straightforward way to confirm that the persistent setting is picked up correctly.

If you prefer to replace the file from a shell, first make sure the name is correct. As root, a command such as printf '%s\n' 'edge-node-02' > /etc/hostname writes one line to the file. Redirection with > overwrites its contents, so do not use it if you need to preserve existing contents.

Choose a valid, useful name

For compatibility across networks and software, use a simple hostname made of letters, digits, and hyphens. A common convention is to begin and end with a letter or digit, keep each label within the DNS limit of 63 characters, and avoid spaces, underscores, and punctuation. A short, descriptive name such as build-runner-1 is easier to recognize than a name that encodes temporary details.

  • Use lowercase letters and hyphens for a predictable, readable style.
  • Avoid names that duplicate another machine’s name on the same local network.
  • Do not include a domain suffix in /etc/hostname unless your environment specifically expects a fully qualified name. A hostname and a fully qualified domain name are related but distinct concepts.
  • Check organizational naming rules if the device is managed by a company, cluster, or hosting provider.

A hostname change alone does not guarantee that other computers can resolve the new name. Name resolution may also depend on DNS, DHCP, mDNS, or local /etc/hosts entries.

Check the result and update related configuration

After changing the name, verify both the active setting and the saved file:

hostname
cat /etc/hostname

If the system uses a local hosts file with an entry for its old hostname, review /etc/hosts and update the relevant entry if appropriate. For example, a line mapping 127.0.1.1 to the old local name may need to use the new name. Do not blindly replace every occurrence: the correct entries vary by setup, and the loopback address 127.0.0.1 should remain the standard localhost address.

On a network where other machines reach this system by DNS name, update the DNS record or the service that manages it. Likewise, container platforms, orchestration systems, DHCP reservations, monitoring software, and cloud dashboards may maintain their own names. The Alpine hostname command changes the local system setting; it does not synchronize those external records.

Common problems and command differences

  • Permission denied: edit /etc/hostname and run the runtime command as root. Use su or configured sudo as appropriate.
  • The old name returns after reboot: confirm that /etc/hostname contains the new name. A runtime-only change is temporary.
  • hostnamectl is missing: that is expected on many standard Alpine installations. Use Alpine’s hostname file and the hostname command rather than assuming systemd tools are available.
  • Other computers still show the old name: check DNS, DHCP, local hosts files, or the relevant network service. A local rename does not instantly update every name cache or directory.
  • The prompt still looks unchanged: an existing shell may not refresh its prompt automatically. Open a new shell or inspect the result with hostname.

For a conventional Alpine host, changing /etc/hostname is the appropriate persistent configuration method. Avoid adding a separate startup command to set the hostname unless a particular image or management system requires it; duplicate configuration can make it unclear which setting is authoritative.

Frequently Asked Questions

Does changing the Alpine hostname require a reboot?
No, the active name can be changed immediately with hostname new-name. A reboot is not required to use the runtime value, but it is a useful way to verify that /etc/hostname preserves the change.

Is the hostname change permanent after editing /etc/hostname?
The file is the persistent setting, but a running system may continue using its current runtime name until it is set with the hostname command or restarted. Do both for an immediate and persistent change.

Can I use hostnamectl on Alpine Linux?
Usually it is not the right tool on a typical Alpine installation, which commonly does not use systemd. Use /etc/hostname for persistence and hostname to set or inspect the active name.

Will changing the hostname change my IP address?
No. The hostname and IP address are separate settings. DHCP or network configuration determines the address, while DNS or other name services may map a hostname to an address.

How do I see my current hostname?
Run hostname to see the active name. Use cat /etc/hostname to see the saved hostname that Alpine can use at startup.

Alpine Linux Change Hostname: Temporary and Permanent
Scroll to top