How to Install and Configure Postfix on Ubuntu Linux

|

|

This tutorial guides new users and students on installing and configuring the Postfix mail server on Ubuntu systems. Postfix, an open-source and free mail transfer agent that focuses on security, can be installed using a simple command. The installation process involves selecting Postfix configuration settings, choosing a mail system name, and modifying the main configuration…

This brief tutorial shows students and new users how to install and configure the Postfix mail server on Ubuntu 18.04 | 16.04 servers.

There are several reasons why one would want to install and configure Postfix on Ubuntu Linux, some of which include:

1. Email Communication: Postfix can set up a mail server to send and receive emails within an organization or even externally. This means that you can use Postfix to create a private email system that can be accessed by the employees of an organization.

2. Security: Postfix is known for its robust security features, which makes it a popular choice for many system administrators. Its security features include access controls, SMTP authentication, and encryption, among others.

3. Open Source: Postfix is an open-source software and free to use. This makes it an excellent choice for those who want a reliable mail server that is also budget-friendly.

4. Compatibility: Postfix can be installed on most Linux systems, including Ubuntu. This means you can easily set up a mail server on your Ubuntu system without switching to a different operating system.

5. Customizability: Postfix is highly customizable, making it a popular choice for those who want to create a mail server that meets their needs. With Postfix, you can configure various settings, including mail server hostname, domain name, and trusted networks, among others.

Overall, installing and configuring Postfix on Ubuntu Linux is a great way to create a reliable and secure email system that can be customized to meet your specific needs.

To get started, follow the steps below:

Install Postfix on Ubuntu

Postfix packages are available via Ubuntu default repositories. Using a simple command, you’ll be able to install it in no time.

To get Postfix installed, run the commands below:

sudo apt update
sudo apt install postfix

When prompted whether to accept the packages that will be downloaded and installed, type y for Yes.

During the installation, you can choose Postfix configuration settings by selecting its configuration site and the mail system name or domain name.

Package configuration

                ┌───────────────────────────┤ Postfix Configuration ├───────────────────────────┐
                │ Please select the mail server configuration type that best meets your needs.  │ 
                │                                                                               │ 
                │  No configuration:                                                            │ 
                │   Should be chosen to leave the current configuration unchanged.              │ 
                │  Internet site:                                                               │ 
                │   Mail is sent and received directly using SMTP.                              │ 
                │  Internet with smarthost:                                                     │ 
                │   Mail is received directly using SMTP or by running a utility such           │ 
                │   as fetchmail. Outgoing mail is sent using a smarthost.                      │ 
                │  Satellite system:                                                            │ 
                │   All mail is sent to another machine, called a 'smarthost', for delivery.    │ 
                │  Local only:                                                                  │ 
                │   The only delivered mail is the mail for local users. There is no network.   │ 
                │                                                                               │ 
                │ General type of mail configuration:                                           │ 
                │                                                                               │ 
                │                           No configuration                                    │ 
                │                           Internet Site                                       │ 
                │                           Internet with smarthost                             │ 
                │                           Satellite system                                    │ 
                │                           Local only                                          │ 
                │                                                                               │ 
                │                    <Ok>                     <Cancel>
                │           
                │                                                                               │ 
                └───────────────────────────────────────────────────────────────────────────────┘ 
                                                                                                  

When prompted, choose Internet Site as highlighted above.

Next, choose a domain name for the mail system.

  ┌─────────────────────────────────────────┤ Postfix Configuration ├──────────────────────────────────────────┐
  │ The "mail name" is the domain name used to "qualify" _ALL_ mail addresses without a domain name. This      │ 
  │ includes mail to and from : please do not make your machine send out mail from root@example.org      │ 
  │ unless root@example.org has told you to.                                                                   │ 
  │                                                                                                            │ 
  │ This name will also be used by other programs. It should be the single, fully qualified domain name        │ 
  │ (FQDN).                                                                                                    │ 
  │                                                                                                            │ 
  │ Thus, if a mail address on the local host is foo@example.org, the correct value for this option would be   │ 
  │ example.org.                                                                                               │ 
  │                                                                                                            │ 
  │ System mail name:                                                                                          │ 
  │                                                                                                            │ 
  │ maill.example.com_________________________________________________________________________________________ │ 
  │                                                                                                            │ 
  │                               <Ok>                                   <Cancel>                              │ 
  │                                                                                                            │ 
  └────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ 
                                                                                                                 

Once the installation is complete, you can stop, start, and enable the service using the commands below:

sudo systemctl stop postfix
sudo systemctl start postfix
sudo systemctl enable postfix

Then, the enable command enables the service to start automatically every time the system boots up.

Configure Postfix

Now that Postfix has been installed move below to learn how to configure it.

Like many other mail servers, Postfix has many different configuration options. Some are basic, while others are more advanced.

Postfix main configuration file is located at /etc/postfix/main.cf

Run the commands below to open its default configuration file:

sudo nano /etc/postfix/main.cf

The majority of Postfix settings are found in this configuration file. At the bottom of the file, you’ll find all the lines with configuration options you’ll need to set up your environment.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = ubuntu1804.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, mail.example.com, ubuntu1804, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

Three to four main configuration options are primarily configured in a live environment: myhostname, mydestination, mynetworks, and mail home folder.

These are details for some of the configurations above:

  • myhostnme: describes the mail server hostname or system name. Normally, it’s a fully qualified hostname:
    • mailsr.example.com
  • mydomain: describes the domain Postfix is handling mail for
    • example: example.com
  • mynetworks: describes the trusted networks of remote SMTP servers that can relay through the server
    • example: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
  • home_mailbx: describes the user’s home mailbox.
    • example: home_mailbox = Maildir/

Besides the configuration options above, Postfix has self-signed certificate settings configured on the system.

Postfix self-signed SSL certificate settings are in the same configuration file mentioned above.

TLS configuration lines look similar to the ones below:

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes

Many other Postfix configurations are located in the /etc/postfix directory. You may have to review files in its leading directory for more advanced configuration help.

When connecting to the service for the first time, you will receive a warning message because they are self-signed and not CA certificates.

Conclusion:

This post shows you how to install and configure the Postfix mail server on Ubuntu. If you find any error, please report it in the comment form below.

You  may also like the post below:


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading