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.
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
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.
- Ubuntu Linux Change Hostname (computer name)
- Debian Linux: Change Hostname / Computer Name Permanently
- Linux change my hostname / computer system name
- Linux Change Hostname
- RHEL / Centos Linux 7: Change and Set Hostname Command
- OpenBSD Change Hostname
- CentOS Linux 5/6 Change Hostname Command
- Linux setting hostname and domain name of my server
- FreeBSD Change Hostname without reboot
- SuSe Linux Change Hostname without reboot
- How to set the hostname on Fedora Linux
- Ubuntu 18.04 LTS change hostname permanently
- Ubuntu set hostname permanently (computer name) command
- OpenSUSE Linux set hostname permanently (computer name) command
- RHEL 8 Linux set hostname permanently (computer name) command
- CentOS 8 Linux set hostname permanently (computer name) command
- Ubuntu 20.04 LTS set hostname permanently (computer name) command
- Set / Change FQDN on Ubuntu 20.04 LTS
- Alpine Linux - Setting system hostname
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |