Alpine Linux Change Hostname (computer name)

I am a new Alpine Linux user. By default, my server name is set to ‘localhost’ during installation. Now, I would like to change the computer name. How do I change the Alpine Linux computer name? Can you tell me more about Alpine Linux change hostname command?

We use the hostname command to get or set the hostname or DNS domain name on Alpine Linux. Since it is a systemd free system, there is no hostnamectl. Alpine Linux comes with OpenRC as an init system. Hence the procedure to change or update hostname is different. This page explains how to change hostname on Alpine Linux using the CLI.

ADVERTISEMENTS

Displaying hostname on Alpine Linux

Run the following command to view current hostname:
hostname
Outputs:

localhost

To see fully qualified domain name, run:
hostname -f

localhost.localdomain

Changing Alpine Linux hostname

Alpine Linux change hostname with the following syntax:
# hostname {new-hostname-here}
# hostname ln-sg-vpn-1

Setting system hostname permanently

To set the system hostname, edit the /etc/hostname file as root user. For example:
# vi /etc/hostname
## OR ##
# nano /etc/hostname

Delete existing name and add a new name such as:
ln-sg-vpn-1
Save and close the editor. Another option is to use the echo command to overwrite this file:
# echo "ln-sg-vpn-1" > /etc/hostname
Immediately activate the change by running the following command. In other words use the /etc/hostname file’s content as hostname:
# hostname -F /etc/hostname
Make sure you update the /etc/hosts file too with a staic IP configuration:
# vi /etc/hosts
The syntax is:

ipv4.here     ln-sg-vpn-1
ipv6.here     ln-sg-vpn-1
# we can use FQDN too #
192.168.2.250 ln-sg-vpn-1.cyberciti.biz
Save and close the vim editor.
Alpine Linux Change Hostname computer name command
NOTE: No need to reboot the system.

Getting help

Run the following command:
hostname --help
The hostname command comes from BusyBox version 1.31.1. It is multi-call binary. The syntax is as follows get or set hostname and DNS domain name:
Usage: hostname [OPTIONS] [HOSTNAME | -F FILE]
Where,

  • -s : Short name of the system
  • -i : Addresses for the hostname
  • -d : DNS domain name
  • -f : Fully qualified domain name (FQDN)
  • -F FILE : Use FILE’s content as hostname

Conclusion

On Alpine Linux, one can use the hostname command to control the system hostname and set a new name. It is the recommended method for all Alpine Linux users. Another option is to update the /etc/hostname file using a text editor such as nano or vi. You can download Alpine Linux for production or testing purpose.

This entry is 19 of 19 in the Linux/Unix Set hostname Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Change Hostname (computer name)
  2. Debian Linux: Change Hostname / Computer Name Permanently
  3. Linux change my hostname / computer system name
  4. Linux Change Hostname
  5. RHEL / Centos Linux 7: Change and Set Hostname Command
  6. OpenBSD Change Hostname
  7. CentOS Linux 5/6 Change Hostname Command
  8. Linux setting hostname and domain name of my server
  9. FreeBSD Change Hostname without reboot
  10. SuSe Linux Change Hostname without reboot
  11. How to set the hostname on Fedora Linux
  12. Ubuntu 18.04 LTS change hostname permanently
  13. Ubuntu set hostname permanently (computer name) command
  14. OpenSUSE Linux set hostname permanently (computer name) command
  15. RHEL 8 Linux set hostname permanently (computer name) command
  16. CentOS 8 Linux set hostname permanently (computer name) command
  17. Ubuntu 20.04 LTS set hostname permanently (computer name) command
  18. Set / Change FQDN on Ubuntu 20.04 LTS
  19. Alpine Linux - Setting system hostname

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.