On this page
- What exactly is the hostname?
- Which name should I choose?
- How do I set the new hostname?
- How should /etc/hosts look after the change?
- Will the new hostname survive a reboot?
- Which services need a restart after renaming?
- How do I set reverse DNS to match?
- What if something goes wrong after the change?
- Questions
What exactly is the hostname?
The hostname is the name the operating system calls itself. It appears in your shell prompt, in every log line, in email headers sent by local programs and in monitoring dashboards. It lives in /etc/hostname and is read by systemd at boot.
systemd tracks three related values:
- static: the name stored in
/etc/hostname, used after every boot - transient: the name the kernel uses right now, normally equal to the static one
- pretty: an optional free text label such as "Payments API (Frankfurt)"
Two names in our console are separate from this. The hostname field on the Deploy page sets the initial value inside the server, and the label is only a tag shown in your Instances list. Changing either one later in the console does not rename the running system. The guide on instance labels and hostnames explains the console side; this page covers the change inside the OS.
Which name should I choose?
Pick a short, stable name and, ideally, a fully qualified domain name (FQDN) under a domain you control, for example node1.example.net. Valid names follow a few rules:
- letters a to z, digits and hyphens only, no underscores or spaces
- each dot separated part 1 to 63 characters, not starting or ending with a hyphen
- 253 characters at most in total
- lowercase is conventional, because DNS ignores case anyway
Names that describe a role and a number, such as web2 or btc-node1, age better than names that describe a customer or a city, since servers get repurposed and moved. If the server will send mail or run TLS services, the FQDN should also exist in public DNS; the DNS records tutorial shows how to add the A and AAAA records.
How do I set the new hostname?
Use hostnamectl, which updates the static name, applies it to the kernel immediately and writes /etc/hostname for you:
hostnamectl
sudo hostnamectl set-hostname node1.example.net
sudo hostnamectl set-hostname "Payments API" --pretty
hostnamectl statusThe first command shows the current values together with the kernel version and operating system, which is handy for a before and after comparison. The last one should list Static hostname: node1.example.net. Some admins prefer to keep only the short name (node1) as the static hostname and let the FQDN come from /etc/hosts; both approaches work, as long as hostname -f returns the full name you expect.
How should /etc/hosts look after the change?
Map the new name to an address so that programs calling gethostbyname() on their own name get an answer even when DNS is slow or missing. Debian and Ubuntu use a special loopback address, 127.0.1.1, for this purpose:
sudo nano /etc/hosts127.0.0.1 localhost
127.0.1.1 node1.example.net node1
::1 localhost ip6-localhost ip6-loopbackOn Rocky Linux and AlmaLinux you can do the same, or map the name to the public address instead, which some software (clustered databases, mail servers) prefers:
198.51.100.24 node1.example.net node1
2001:db8:4f2a::24 node1.example.net node1Put the FQDN first and the short name after it. Remove any line that still carries the old name. Then test:
hostname
hostname -f
getent hosts node1.example.netWill the new hostname survive a reboot?
On a plain system, yes: /etc/hostname is read at every boot. Some images include cloud-init, which can reset the hostname from its own data at startup. Check whether it is installed and, if so, tell it to leave the name alone:
ls /etc/cloud/cloud.cfg 2>/dev/null && grep -n preserve_hostname /etc/cloud/cloud.cfgIf the file exists, create a small override rather than editing the main file:
echo 'preserve_hostname: true' | sudo tee /etc/cloud/cloud.cfg.d/99-keep-hostname.cfgIf the first command prints nothing, cloud-init is not present and no override is needed. Either way, prove it with a planned restart, either sudo systemctl reboot or the Restart button on the instance page, and run hostnamectl once you are back.
Which services need a restart after renaming?
Programs that read the hostname at startup keep the old value until they restart. Your own shell is one of them: the prompt changes only after you log out and in again, or start a fresh shell with exec bash. Common server software to check:
- rsyslog and journald: new log lines pick up the name; restart
rsyslogif you forward logs - Postfix:
myhostnamein/etc/postfix/main.cfand/etc/mailnameon Debian systems - monitoring agents: many register the host by name, so the old entry may need to be removed in the dashboard
- databases with replication: some identify nodes by hostname
grep -rl "oldname" /etc 2>/dev/null
sudo systemctl restart rsyslogThe grep line finds configuration files that still carry the previous name so nothing is missed.
How do I set reverse DNS to match?
Reverse DNS (the PTR record) maps the IP address back to a name, and mail servers in particular check that it matches the hostname. PTR records are not a console setting at BitcoinVPS: open a ticket with the IPv4 or IPv6 address and the FQDN you want, and support sets it for you. Make sure the forward A or AAAA record already points to the server before you ask. You can check both directions afterwards:
dig +short node1.example.net A
dig +short -x 198.51.100.24When planning a mail server, also ask in the same ticket about outgoing port 25, because direct delivery is not guaranteed; an authenticated relay on port 587 is the dependable route.
What if something goes wrong after the change?
The most common symptom is a slow sudo that prints unable to resolve host. It means the new name has no entry in /etc/hosts. Add the line shown above and the delay disappears. Other quick checks:
cat /etc/hostname
hostnamectl
journalctl -b -u systemd-hostnamed --no-pager | tailIf /etc/hostname and hostnamectl disagree after a reboot, something rewrote the file at startup, usually cloud-init as described above. To go back to the previous name, simply run set-hostname again with the old value and restore the old /etc/hosts line.
Questions about Change the hostname
Do I need to reboot after changing the hostname?
No. hostnamectl set-hostname applies the change at once. A reboot is only useful to prove the setting persists and to make every service pick up the new name.
Can I change the hostname from the BitcoinVPS console?
The hostname field on the Deploy page sets the starting name. After deploy, rename the server inside the OS with hostnamectl; the console label is only a tag in your Instances list.
Should the hostname be a real domain?
It does not have to be, but a fully qualified name under a domain you own is the cleanest choice, especially for mail, TLS and monitoring. Avoid made up public suffixes that someone else might register.
Why does sudo print unable to resolve host?
The new name is missing from /etc/hosts. Add a line such as 127.0.1.1 node1.example.net node1 and the message stops.
Is the same command used on FreeBSD?
No. FreeBSD keeps the name in /etc/rc.conf; set it with sysrc hostname="node1.example.net" and apply it with hostname node1.example.net.
More in Server basics
- Create a sudo user
- Add a swap file
- Time zone and time sync
- File and directory permissions
- Choose a Linux distribution
- Upgrade Ubuntu to the next LTS
- Upgrade Debian to a new major release
- Rocky or AlmaLinux to a new major version
- Automatic security updates
- Run an app as a systemd service
- Schedule jobs with cron and systemd timers
- Environment variables on Linux
- Check disk space and find what fills it
- Inspect processes and memory
- Read the hardware and system report
- Reboot and shut down safely
- Customise the login message (MOTD)
- Remote desktop with Xfce and xrdp
- SELinux on Rocky Linux and AlmaLinux
- Keep sessions alive with tmux
- SFTP-only users in a chroot
- apt and dnf package management
- First-hour checklist for a new server
- Upgrade FreeBSD to a new release