A server has a short name and a fully qualified name, and three separate things have to agree about them: the kernel, the hosts file and DNS. Set one and not the others and everything appears to work until mail is rejected or sudo pauses for ten seconds on every command.
Set it
sudo hostnamectl set-hostname web1.example.com
hostnamectl
Then the hosts file
This is the part that is usually missed. The machine must be able to resolve its own name without asking DNS.
# /etc/hosts
127.0.0.1 localhost
127.0.1.1 web1.example.com web1
The ten-second pause before every sudo command is this file. sudo looks the hostname up, the lookup times out, and then it carries on as normal.
Then DNS
An A record for web1.example.com pointing at the server, and a reverse record from the IP back to that name. The forward record you control; the reverse one is set by whoever owns the IP - your provider.
Why mail cares
- A receiving server checks that the name your server gives in HELO resolves, and that the IP resolves back to it.
- A mismatch is one of the strongest spam signals there is, and it is applied before your content is even read.
- This is the same check described in reverse DNS for a mail server.
Confirm
hostname -f # the fully qualified name
getent hosts $(hostname -f)
dig +short web1.example.com
Do this before installing anything. Several packages read the hostname at install time and write it into their own configuration, so changing it afterwards means editing them all.