Linux, Web Server & Database
Configure Server Hostname
Set a proper, meaningful hostname for your server instead of the default auto-generated one.
The Problem
Your server still has the generic hostname your VPS provider auto-assigned, which makes it harder to identify at a glance in logs, prompts and monitoring tools, especially once you're managing more than one server.
About this problem
A default hostname like a random string of letters and numbers works fine technically, but becomes a real annoyance once you're juggling multiple servers and need to tell them apart quickly in your terminal prompt, logs, or monitoring dashboard — a proper hostname also matters for some services (like mail servers) that use it as part of their own identification.
This is usually done as a small piece of initial server setup, or after realising every server's prompt looks identical and confusing.
What's Included
- Setting a clear, descriptive hostname matching your naming convention
- Updating /etc/hosts so the hostname resolves correctly to localhost
- Confirming the change persists correctly across a reboot
- Checking whether any running services reference the old hostname and need updating
What's NOT Included
- DNS record changes for a public-facing hostname/subdomain (separate service if needed)
- Renaming a server that's actively part of a cluster or mail setup relying on the current hostname (needs extra care, flagged if detected)
- Choosing your naming convention — that's your call
How It Works
- Set the new hostname using hostnamectl set-hostname.
- Update /etc/hosts to map the new hostname to 127.0.1.1 (or equivalent) alongside localhost.
- Confirm the change with hostname and hostnamectl status.
- Restart or reconnect a session to confirm prompts and services reflect the new name correctly.
- Check mail server, monitoring agent, or clustering configs for any hardcoded reference to the old hostname.
In practice: you buy the service, send over whatever access or details the job needs, I investigate and do the work, and you confirm it's resolved before we call it done.
Frequently Asked Questions
- Will changing my hostname break anything?
- Usually not for a standalone web/app server, but it's worth checking if any service (particularly mail servers or clustering software) has the old hostname hardcoded somewhere in its config.
- What's a good naming convention for server hostnames?
- Something that identifies purpose and environment at a glance, like app-prod-01 or db-staging — the specific convention matters less than being consistent across all your servers.
- Do I need to update DNS after changing the hostname?
- Only if you have a DNS record pointing at the server by its old hostname specifically — the system hostname and public DNS names are separate things that don't update each other automatically.
- Why does my terminal prompt still show the old hostname?
- Some shells cache the hostname at login, so reconnecting a fresh SSH session (rather than reusing an existing one) usually shows the updated value immediately.
- Is hostname the same as domain name?
- No — hostname identifies the machine itself at the system level, while a domain name is what the public internet uses to find your site via DNS; they can match but don't have to.
- Can two servers have the same hostname?
- Technically yes on separate networks, but it causes real confusion in logs, monitoring and SSH known_hosts — each server should have a unique, identifiable hostname.