How to set your server hostname and rDNS
Setting the hostname is one command; reverse DNS has to be set by whoever owns the IP address, which for a VPS means asking your host.
Set the hostname itself with hostnamectl set-hostname, which you can do yourself in one command. Reverse DNS (rDNS) is different — it is controlled by whoever owns the IP address, which on a VPS is your host, so that has to be requested from them rather than set locally.
Setting the hostname
sudo hostnamectl set-hostname web1.yourdomain.com
Confirm it took effect:
hostnamectl
Some older tools and scripts also read /etc/hosts directly, so update that file to match:
sudo nano /etc/hosts
127.0.1.1 web1.yourdomain.com web1
A fully qualified hostname like web1.yourdomain.com is generally the better choice over a bare name, particularly if the server sends email — many spam filters check that a server's hostname resembles a real domain rather than a generic default.
Why reverse DNS is different
Forward DNS answers "what IP address does this name point to?" and you control that through your own domain's DNS. Reverse DNS answers the opposite question — "what hostname does this IP address point to?" — and that record lives in DNS zones controlled by whoever owns the IP address block, not by you. On a VPS, that is your hosting provider, so you cannot set it yourself no matter what you change on the server.
Requesting rDNS
Contact your host and ask for a PTR record to be set for your VPS's IP address, pointing at the hostname you have configured on the server — for example, requesting that 203.0.113.10 resolves in reverse to web1.yourdomain.com. Contact us with your server's IP and the hostname you want if this applies to your VPS.
Ideally, the hostname your host sets in reverse DNS should also resolve forward, via a normal A record on your own domain, back to the same IP address. Mail servers in particular check for this match, and a mismatch is a common, avoidable reason legitimate outgoing mail gets treated with suspicion.
When this actually matters
- Sending email from the server. Missing or mismatched rDNS is one of the most common reasons a mail server's outgoing messages are marked as spam or rejected outright.
- Running any service that logs or displays the connecting hostname to identify itself to others.
- General good practice — a server with a real, matching hostname is easier to identify in logs, monitoring, and your own inventory once you are managing more than one.
If the server is purely serving a website and not sending mail directly, a mismatched or default rDNS entry is unlikely to cause a visible problem — it matters most for anything sending outbound email or identifying itself by hostname to another system.
Related reading
The order of operations for a fresh VPS, from your first SSH login through to a locked-down server ready for a website.
How to host a domain on your VPSPointing a domain at your VPS is DNS plus a matching web server config — here is both halves, and how to check they agree.
How much RAM does my VPS need?It depends what is running, but free -h on an existing server and a look at what each extra service costs gets you a real answer fast.
How to add swap space to a VPSCreating a swap file with fallocate and mkswap, making it permanent in fstab, and why swap is a cushion rather than a substitute for RAM.