This article explains how to install Postfix on Ubuntu 24.04.
Postfix, an open-source mail transfer agent (MTA), was developed as a secure and efficient alternative to the widely used Sendmail program. It lets you set up a mail server to send and receive emails.
Postfix has robust security features, including support for TLS encryption, ensuring your email communications are secure and protected. It can be easily integrated with other services, like SpamAssassin for spam filtering or Dovecot for IMAP/POP3 services.
The steps below walk you through installing Postfix on Ubuntu Linux.
Install Postfix
Postfix is an MTA and works with many email servers. The command below installs Postfix with SMTP-Auth to use Dovecot’s SASL.
sudo apt update
sudo apt install postfix sasl2-bin
During the installation, you will be prompted to select the 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 installing Postfix, copy the generic distribution configuration file to create a new one.
sudo cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf
Then, open the configuration file and adjust 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 and exit the file.
Restart Postfix.
sudo newaliases
sudo systemctl restart postfix
Postfix should be installed and ready to use.
Additional SPAM protection
Additional configuration can be added to the config file above to combat SPAM. However, you must handle with care.
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.
Leave a Reply