How to Install Postfix on Ubuntu Server (with Pictures)
Edit Article

  • 1 Editor

Postfix is one of the most popular and famous Mail Transfer Agent (MTA), which is open source. It can be used to route and then deliver the emails on a Linux system. Approximately 25% of the public mail servers present on the internet are running Postfix.

So in this article, I am going to tell you that how can you install postfix on your Ubuntu server.


If you want to follow this article, then you should have your own domain name, and a Ubuntu server. In this article, I will be using Ubuntu 14.04 server.

Installation of software

It is very easy to install the postfix on Ubuntu 14.04, because this software is included in the default package repositories of Ubuntu.

First, we are going to update the local package index, and then we are going to install the Postfix package.

Enter the following command:

sudo apt-get update sudo apt-get install postfix

After entering this command, you will be asked that what type of mail configuration you want your server to have. For our server, the description is the best match so we will be choosing “Internet Site”, for our purposes.

After that, for your server, you will be asked to enter the FQDN (Fully Qualified Domain Name). This will be the full name of your domain, (e.g. If we talk a bit technically, then you required to end the FQDN with a dot, but it is not needed by Postfix. So it can simply be like this:

Now by using the settings that you provided, the software will now be configured. The installation is taken care by it, but still there are other items that we were not prompted for during the installation, and we have to configure them.

Configuring Postfix

Now we have to make some changes in the basic settings in the main Postfix configuration file. Now you can begin by opening this file with root privileges in the text editor. Enter the following command:

sudo nano /etc/postfix/

The first thing is that now we have to find the parameter myhostname. While configuring, the FQDN that we selected was added to the parameter which is mydestination, and the parameter myhostname remained set to localhost. Now we have to point it to our FQDN too:

myhostname =

If you want the configuration of forwarding your mail to the other domains or if you wish to deliver the addresses that don’t map 1-to-1 with the system accounts, then you can do so by removing the alias_maps parameters, and the typing virtual_alias_maps in its place. After that, the location of the has to be changed to /etc/postfix/virtual :

virtual_alias_maps = hash:/etc/postfix/virtual

As you already know that the mydestination parameter has already been modified during installation, with FQDN. All of the domains that this installation of Postfix is responsible for, will be held in this parameter. It is configured for the localhost and the FQDN.

mynetworks parameter is one of the most important one to mention. This parameter will define the computers which will be able to use this mail server. It should be set to local only For allowing other hosts to use this, by modifying it, is a big security vulnerability, and it can lead to severe spam cases.

Just for your clarification, the line should be written like this:

mynetworks = [::ffff:]/104 [::1]/128

Additional Email addresses Configuration

By creating aliases, we can configure additional email addresses. We can deliver mail to other user accounts on the system, through these aliases. You have to make sure that you configured the directive virtual_alias_maps just like I told you before, if you want to use this functionality. To configure our address mappings, we will use this file. You can create the file by typing the following command:

sudo nano /etc/postfix/virtual

On the left hand side of this file, you can specify the emails that you wish to create. And on the right hand side, you can write the username to which you want to deliver the mail. It will be something like this: username001

Now we are going to create some email addresses and then route them to some user accounts, for our installation. Certain addresses can also be set up to forward to multiple accounts by using a list separated by comma.


Now when you are finished, then you have to save and then close this file. Now by entering this command, we can implement our mapping:

sudo postmap /etc/postfix/virtual

Now in order to read our changes, we have to reload our services. Enter the following command:

sudo service postfix restart

Testing your configuration

Now the next step is that you have to test if your server can receive and then route mails correctly by sending mail, to one of your user accounts on the server from your regular email address, or one of the aliases you set up. When you send the email to:

Now a mail should be delivered to a file that matches the delivery username in /var/mail. For example, we can read this message by looking at this file:

nano /var/mail/demouser

All of the email messages, along with the headers, will be contained in it in one big file. You may want to install a few more helping programs, if you want to interact with your email in a more user friendly way. Enter the following command:

sudo apt-get install mailutils

By doing this, you will be given access to the mail program that can be used to check your inbox.


By doing this, an interface will be given to you, through which you can interact with your mail. Now basic email functionality has been configured to your server.

Now the important thing is that you have to secure your server, and you have to make sure that Postfix is not configured as an open relay.

So this was how you can install and setup Postfix on your server. I hope this article was helpful for you.

See you soon. Thanks !!

Article Tools

Did this article help you?


an Author!

Write an Article