跳到正文
Email Servers

Install and Configure Postfix on Ubuntu: The Essentials

sudo apt install postfix, choose “Internet Site”, set the FQDN, then review myhostname, mydomain, mydestination and inet_interfaces in /etc/postfix/main.cf and restart.

测试环境 Ubuntu 24.04 LTS, Postfix 3.8

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

Terminal
sudo apt updatensudo apt install postfix
  1. When asked for the configuration type, choose Internet Site.
  2. For System mail name, enter your domain or the server’s fully qualified name, e.g. mail.example.com.
  3. Postfix installs and starts automatically.

Step 2 – Review main.cf

Terminal
sudo nano /etc/postfix/main.cf
SettingSet it toWhy
myhostnameThe server’s FQDN, e.g. mail.example.comUsed in the SMTP greeting – should match the PTR record
mydomainexample.comBase domain for other defaults
mydestination$myhostname, localhost.$mydomain, localhost, $mydomainDomains this server delivers locally
inet_interfacesall (or loopback-only for send-only servers)Which interfaces accept mail
mynetworks127.0.0.0/8 [::1]/128Who may relay without authentication – keep it tight

Step 3 – Restart and check

Terminal
sudo postfix checknsudo systemctl restart postfixnsudo systemctl status postfix u002du002dno-pager

Send a test message and watch the log:

Terminal
echo u0022Test from $(hostname)u0022 | mail -s u0022Postfix testu0022 you@example.comnsudo tail -f /var/log/mail.log

Before 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.

Inder Kochar

作者

Inder Kochar

系统与网络工程师 – 我把为客户使用的解决方案整理成文,并在真实系统上测试过。遇到类似问题了吗?

继续阅读

提出问题或分享您的解决方法

您的邮箱不会公开。评论需经审核——请围绕主题发言。