How to Install Postfix on Ubuntu 24.04
Postfix on Ubuntu 24.04 sets up a mail server to send and receive emails for your website or domain. It works as a mail transfer agent, which is the software that moves messages from your computer to other servers across the internet.
You can install this email tool in just a few minutes using the standard Ubuntu software tools. Running your own mail server lets you handle email directly without paying for a third-party service.
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
The package manager installs the mail server binaries alongside basic delivery utilities. Run the package manager command, then press Enter when prompted to accept the default settings: '[No configuration]'.
sudo apt update
sudo apt install postfix sasl2-bin
Choose the general mail configuration type on the following screen, proceeding with [No configuration].
┌─────┤ Postfix Configuration ├─────┐
│ General mail configuration type: │
│ │
│ No configuration │
│ Internet Site │
│ Internet with smarthost │
│ Satellite system │
│ Local only │
│ │
│ │
│ <Ok> <Cancel> │
│ │
└───────────────────────────────────┘
Manual environment configuration follows the package installation.
Copy the default template to establish a working configuration file.
sudo cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf
Open the new file and insert the required parameter changes.
sudo nano /etc/postfix/main.cf
Refine the networking parameters.
# 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
Commit the modifications and close the editor.
Apply the configuration changes by restarting the service.
sudo newaliases
sudo systemctl restart postfix
The messaging service is now active and listening for connections.
Additional SPAM protection
Unwanted junk mail gets blocked through sender domain validation checks. Adding an extra layer of security requires editing the main configuration file located at `/etc/postfix/main.cf`. Append the validation rules to the end of the configuration document.
Paste the filtering parameters at 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 the mail server daemon to load the new filters.
The messaging infrastructure is fully operational.
Conclusion:
Configuring Postfix on Ubuntu 24.04 establishes a secure foundation for mail delivery. Review these core concepts:
- 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 these deployment steps enables robust mail management capabilities across the entire system.
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 […]