How to Install Postfix on Ubuntu 24.04
You install Postfix on Ubuntu 24.04 to set up a secure and efficient mail server.
Postfix is an open-source Mail Transfer Agent (MTA), the program responsible for sending and receiving emails. It’s a popular alternative to older MTAs like Sendmail.
This guide walks you through installing Postfix on Ubuntu 24.04, configuring it to handle your email needs.
By default, the Postfix installation on Ubuntu 24.04 provides a solid foundation for most common mail server tasks.
Install Postfix by running sudo apt update and sudo apt install postfix sasl2-bin. During installation, select “No configuration” then copy the default config with sudo cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf.
Install Postfix
To install Postfix on Ubuntu 24.04, you’ll use the terminal to run a simple command that installs the Postfix mail server along with tools for secure email sending.
sudo apt update
sudo apt install postfix sasl2-bin
You’ll then be prompted to choose a mail configuration and proceed with [No configuration].
┌─────┤ Postfix Configuration ├─────┐
│ General mail configuration type: │
│ │
│ No configuration │
│ Internet Site │
│ Internet with smarthost │
│ Satellite system │
│ Local only │
│ │
│ │
│ <Ok> <Cancel> │
│ │
└───────────────────────────────────┘
We will manually set up your environment.
After installation, copy the default configuration file to create your own.
sudo cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf
Open this new file and make the highlighted changes.
sudo nano /etc/postfix/main.cf
Adjust your settings.
# QUEUE AND PROCESS OWNERSHIP
#
mail_owner = postfix
# INTERNET HOST AND DOMAIN NAMES
#
myhostname = srv1.example.com
# The mydomain parameter specifies the local internet domain name.
#
mydomain = example.com
# Debian GNU/Linux specific:The Debian default is /etc/mailname.
#myorigin = /etc/mailname
#myorigin = $myhostname
myorigin = $mydomain
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on.
inet_interfaces = all
# Specify a list of host or domain names, /file/name or type:table
#
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# Details are described in the LOCAL_RECIPIENT_README file.
#
local_recipient_maps = unix:passwd.byname $alias_maps
# Specify "mynetworks_style = host" when Postfix should "trust"
#
#mynetworks_style = class
mynetworks_style = subnet
# Specify an explicit list of network/netmask patterns, where the
#mynetworks = 168.100.3.0/28, 127.0.0.0/8
mynetworks = 192.168.156.0/24, 127.0.0.0/8
# ALIAS DATABASE
#
# The alias_maps parameter specifies the list of alias databases used
# by the local delivery agent. The default list is system dependent.
#alias_maps = dbm:/etc/aliases
alias_maps = hash:/etc/aliases
#alias_database = dbm:/etc/aliases
#alias_database = dbm:/etc/mail/aliases
alias_database = hash:/etc/aliases
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
home_mailbox = Maildir/
# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server's greeting banner.
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
#smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_banner = $myhostname ESMTP
# INSTALL-TIME CONFIGURATION INFORMATION
# sendmail_path: The full pathname of the Postfix sendmail command.
# This is the Sendmail-compatible mail posting interface.
#
sendmail_path = /usr/sbin/postfix
# newaliases_path: The full pathname of the Postfix newaliases command.
# This is the Sendmail-compatible command to build alias databases.
#
newaliases_path = /usr/bin/newaliases
# mailq_path: The full pathname of the Postfix mailq command. This
# is the Sendmail-compatible mail queue listing command.
#
mailq_path = /usr/bin/mailq
# setgid_group: The group for mail submission and queue management
# commands.
setgid_group = postdrop
# add the remaining lines below to the end of the file.
disable_vrfy_command = yes
# require HELO command to sender hosts
smtpd_helo_required = yes
# limit an email size to 10M bytes limit
message_size_limit = 10240000
# SMTP-Auth settings
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
Save your changes and exit the file.
Restart Postfix.
sudo newaliases
sudo systemctl restart postfix
Now, Postfix should be installed and ready to go.
Additional SPAM protection
Adding extra rules to your Postfix setup on Ubuntu 24.04 can help block unwanted SPAM emails, but it’s important to make these changes carefully.
Add to the bottom of the config file.
# reject unknown clients that forward lookup and reverse lookup of their hostnames on DNS do not match
smtpd_client_restrictions = permit_mynetworks, reject_unknown_client_hostname, permit
# rejects senders that domain name set in FROM are not registered in DNS or
# not registered with FQDN
smtpd_sender_restrictions = permit_mynetworks, reject_unknown_sender_domain, reject_non_fqdn_sender
# reject hosts that domain name set in FROM are not registered in DNS or
# not registered with FQDN when your SMTP server receives HELO command
smtpd_helo_restrictions = permit_mynetworks, reject_unknown_hostname, reject_non_fqdn_hostname, reject_invalid_hostname, permit
Restart Postfix.
That should do it!
Conclusion:
Installing Postfix on Ubuntu 24.04 enables you to set up a robust mail server with various security features. Here are the key takeaways:
- User-Friendly Installation: The installation process requires just a few commands.
- Secure Email Management: Postfix supports TLS encryption to ensure secure communications.
- Customizable Configuration: You can easily modify the main configuration file to suit your needs.
- SPAM Protection: Additional configurations can enhance security by reducing SPAM and validating sender identities.
- Integration Ready: Postfix can be integrated with tools like Dovecot and SpamAssassin to create a comprehensive mail handling system.
- Active Maintenance: Regular updates and maintenance will keep your email server running efficiently.
Following the outlined steps, you can successfully implement Postfix and leverage its features for effective email management.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
[…] with various mail protocols (IMAP, POP3) and integrates seamlessly with mail delivery agents like Postfix or […]