Alpine Linux Change Hostname (computer name)

In Alpine Linux, you can change the hostname (computer name) by following these steps:

  1. First, open the system’s hostname configuration file, typically located at /etc/hostname, by running the following command:
nano /etc/hostname
  1. Replace the current hostname with your desired hostname in the file, then save and close the file.
  2. Next, you should also update the hostname in the system’s hosts file located at /etc/hosts, by running the following command:
nano /etc/hosts

In the file, change the name at the first line after 127.0.0.1, with your new hostname.

  1. Now, you need to tell the running system to update the hostname by running the following command:
hostname -F /etc/hostname
  1. Finally, restart the networking service to apply the changes:
rc-service networking restart
  1. You can also use the hostname command to check the current hostname, for example hostname.

It’s important to keep in mind that the changes will only take effect for the current session, if you reboot the machine, the original hostname will be used again. To make the changes permanent you should add the hostname changing command to the startup script like rc.local or systemd script.

Also, note that some applications may have hardcoded the old hostname, and will not work until they are updated or reconfigured.

Leave a Comment