Postfix is the most widely used mail transfer agent on Linux: fast, secure by design and well documented. This guide installs it on Ubuntu and walks through the handful of settings you must get right.
Step 1 – Install Postfix
sudo apt updatensudo apt install postfix- When asked for the configuration type, choose Internet Site.
- For System mail name, enter your domain or the server’s fully qualified name, e.g.
mail.example.com. - Postfix installs and starts automatically.
Step 2 – Review main.cf
sudo nano /etc/postfix/main.cf| Setting | Set it to | Why |
|---|---|---|
myhostname | The server’s FQDN, e.g. mail.example.com | Used in the SMTP greeting – should match the PTR record |
mydomain | example.com | Base domain for other defaults |
mydestination | $myhostname, localhost.$mydomain, localhost, $mydomain | Domains this server delivers locally |
inet_interfaces | all (or loopback-only for send-only servers) | Which interfaces accept mail |
mynetworks | 127.0.0.0/8 [::1]/128 | Who may relay without authentication – keep it tight |
Step 3 – Restart and check
sudo postfix checknsudo systemctl restart postfixnsudo systemctl status postfix u002du002dno-pagerSend a test message and watch the log:
echo u0022Test from $(hostname)u0022 | mail -s u0022Postfix testu0022 you@example.comnsudo tail -f /var/log/mail.logBefore it goes live
A public mail server also needs TLS (smtpd_tls_cert_file / key), SASL authentication for users who send through it (usually via Dovecot), and SPF, DKIM, DMARC and PTR records – otherwise your mail will be rejected or marked as spam. Never leave it as an open relay.
Check the DNS side
Confirm MX and PTR records with the DNS Lookup tool, and authentication records with the SPF, DKIM & DMARC Checker.

