The updated infrastructure management interface

How to Install and Configure Postfix on Ubuntu 20.04

Joe Harris
March 31, 2021

Postfix is a fairly common mail server due to sufficient functionality for most tasks and easy setup. This tutorial will cover the installation and basic configuration of Postfix and the server for it.


The server must have a static public IP address. You will also need a domain name. Let’s first configure the necessary DNS records.
For the mail server, a 3rd level subdomain is usually used. As an example, we will use Replace the with your domain name. The 3rd level domain name can be arbitrary. The main thing is to use the appropriate option in further configuration. DNS records can usually be configured in the control panel of a domain name registrar or on your DNS server.
Add a DNS A record for your domain named mail and «target» equal to the IP address of the future mail server.

mail A

Add DNS MX record for the root domain with a value equal to the domain name of the mail server:

@ MX

If the service returns an error as a result, try not to use nothing instead of @.

Server configuration

With the selected 3rd level domain name, the hostname will be mail. Let’s configure it.

sudo hostnamectl set-hostname mail

Now open the hosts file.

sudo nano /etc/hosts

Let’s add a line for this server with its IP address, your domain name and hostname. This entry must be placed directly below the entry for localhost. mail

Postfix installation

Let’s install Postfix and mail package mailutils.

sudo apt install postfix mailutils

During installation, you will be prompted for options interactively. Set mail server configuration type to Internet Site.

Set mail server configuration type
Screenshot 1. Set mail server configuration type.

System mail name must match the domain name for which we are setting up the mail server. In our case, this is

Set system mail name
Screenshot 2. Set system mail name.

Postfix testing

Now the Postfix mail server is ready to work. Let’s test it and send our first email. Put your mail to the following command and run it:

echo "Postfix test" | mail -s "Subject"

Due to the fact that encryption and things like DKIM are not yet configured, your letter will most likely end up in the Spam folder. Some mail servers like won’t accept it at all. We’ll fix this later.
Now you can reply to this letter in your mailbox and see this answer on the mail server.



"/var/mail/root": 1 message 1 new
>N 1 Sender Name Wed Mar 17 04:32 66/2877 RE: Subject

Enter 1 and you will see your reply.

The next step is to set up Postfix to use virtual mailboxes.

Start Your Cloud Journey Migration made simplified. Take the first step right now.
We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Privacy Policy. By continuing to browse our website, you agree to our use of cookies.