How to Install and Configure a Mail Server in Ubuntu (Postfix)


This guide covers mail server Ubuntu step by step, with every setting in the order you will use it. Postfix is the standard mail server on Linux: fast, secure by default, and the reason most of the internet’s mail runs on it. In a lab it teaches the fundamentals of SMTP, and in production it can both send and receive real mail. This guide installs it on Ubuntu Server.

mail server Ubuntu in a home lab

UBUNTU LINUXMAIL SERVER UBUNTUENTERPRISE LABtimer 45 MIN LAB
NH
Nurul Huda AUTHORInfrastructure & Cloud Architect · Verified 2026

print Print Lab

● VALID ON THE CONFIG BELOW

dns LAB TOPOLOGY & PREREQUISITES

# example values used while writing and testing this guide

LAB VM

HypervisorVMware / ESXi
vCPU2
RAM2-4 GB
Disk40 GB

UBUNTU BUILD

Version24.04 LTS
Accesssudo user
IPstatic or DHCP
SSHenabled in lab

VALIDATION

Statussystemctl
Firewallufw lab rules
Snapshotbefore changes

01constructionMail server Ubuntu: Step 1: Install Postfix

Update packages and install; the installer asks for the mail configuration type:

sudo apt update && sudo apt install postfix -y

Choose Internet Site (sends and receives directly) for a lab, and set the system mail name — your domain, for example lab.local. Skip the wizard options and you can always rerun it later with sudo dpkg-reconfigure postfix.

02downloadStep 2: Understand the Main Settings

Postfix’s configuration lives in /etc/postfix. The key values in main.cf:

  • myhostname — this server’s name, like mail.lab.local
  • mydomain and myorigin — the domain used on outgoing mail
  • mydestination — domains this server accepts mail for locally
  • mynetworks — hosts allowed to relay through this server; keep it to your lab subnet
  • inet_interfaces — which network interfaces it listens on

After any edit, validate and reload: sudo postfix check && sudo systemctl reload postfix. In short, mail server Ubuntu works best when you follow the order above and verify each step.

03usbStep 3: Test Sending Mail

Install a mail utility and send a test:

sudo apt install mailutils -y
echo "Test body" | mail -s "Lab test" user@lab.local

Read the local delivery with the mail command, and watch the log at /var/log/mail.log — every SMTP conversation is logged there, which makes it the best debugging tool you have.

04terminalStep 4: Real-World Notes

Receiving mail from the internet needs port 25 open, a static IP, correct MX records in DNS (see the Ubuntu DNS guide) and matching reverse DNS. Most ISPs block residential port 25, so labs usually pair Postfix with a smart host for outbound delivery. For full mailbox service add Dovecot (IMAP/POP3). Compare with the Windows Server SMTP setup. In short, mail server Ubuntu works best when you follow the order above and verify each step.

Related Content

▶ UP NEXT IN THE UBUNTU TRACK

How to Install and Configure a Database Server in Ubuntu (MySQL/MariaDB)

Finish this lab, then continue down the track. Each guide builds on the one before it.

rocket_launch Launch Next Lab