In Alpine Linux, you can change the hostname (computer name) by following these steps:
- First, open the system’s hostname configuration file, typically located at
/etc/hostname
, by running the following command:
nano /etc/hostname
- Replace the current hostname with your desired hostname in the file, then save and close the file.
- 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.
- Now, you need to tell the running system to update the hostname by running the following command:
hostname -F /etc/hostname
- Finally, restart the networking service to apply the changes:
rc-service networking restart
- You can also use the
hostname
command to check the current hostname, for examplehostname
.
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.