How to install and configure Postfix on Debian

How to install and configure Postfix on Debian
In this tutorial we will show you how to install and configure Postfix on your Debian VPS.


Postfix is one of the most popular Mail Transfer Agent (MTA). It is also free,open-source software what can be used to route and delivers electronic mail on any Linux system.

It is intended as an alternative to the widely used Sendmail MTA and it is estimated that around 25% of public mail servers on the internet run Postfix.


The first thing you need to do before starting with the installation is to log in to your Debian VPS as ROOT via SSH. Once you are in make sure that your Debian system is fully up-to-date by running the following commands in your terminal:

apt-get update
apt-get upgrade


By default Postfix is already available in the Debian repositories so the installation process of Postfix itself on Debian is pretty simple procedure. To start just type on your terminal:

apt-get install postfix

Once the installation start you will be asked what type of mail configuration you want to use for your server. Choose “Internet Sitetype the number 2 on the prompt and press “ENTER
How to install and configure Postfix on your Ubuntu 14.04 VPS

Next, you will need to enter the Fully Qualified Domain Name (FQDN) for your server. In most cases that will be your main domain name that you will use to send emails. So type it and click “ENTER” again:
How to install and configure Postfix on your Ubuntu 14.04 VPS
And that’s it, the installation will now continue and finish, but we still need to configure some other items that we were not prompted to be configured during installation.


First thing we need to do is to set the myhostname parameter. By default it should be set to localhost but it had to be pointed to the FQDN that we set during the installation. To do that edit:

nano /etc/postfix/

and change:

myhostname = localhost


myhostname =

Next, if you want your e-mails to be forwarded to other domains or users that you have or you want to deliver to addresses that don’t map 1-to-1 with system accounts you will need to remove:


and add a new one virtual_alias_maps parameter. Please note that is such case you will also need to change the hash location to /etc/postfix/virtual

virtual_alias_maps = hash:/etc/postfix/virtual

Other thing that you need to change is the mynetworks parameter. Here you can tell Postfix which IP addresses should be able to connect and use the mail system. It should be set to local only ( and the other representations) but If for any reason you need to modify it please be very careful with what are you doing because you may accidentally allow other hosts to use your mail server what can be a huge vulnerability which can lead to extreme cases of spam.
To be more specific the line should look like this and it should be also setup like this automatically, but never hurts to double check the value:

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

Save and close the file and restart the Postfix service for the changes to take effects:

service postfix restart


If you want to setup any additional email addresses you can do that by creating aliases. You can use these aliases to be able to deliver mail to other user accounts on the system.
To enable and use this function you will need to make sure to configure the virtual_alias_maps parameter (which we already did in the previous caption). To start first create a new file:

touch /etc/postfix/virtual

edit the file:

nano /etc/postfix/virtual

And in this file you can specify the additional email addresses that you want to create. You will need to put them on the left side in the file, and put the username where you want the emails to be deliver on the right side. Something like this:

[email protected] the_username

Do not forget to replace [email protected] and the_username with a correct/real email and username.
Save and close the file when you are finished.
Now, we can implement our mapping by executing this command:

postmap /etc/postfix/virtual

And restart the Postfix service again for the changes to take effects.

service postfix restart

If you’re one of our Linux VPS Hosting customers we can help you to install and configure Postfix on your virtual server for you free of charge. Just contact us and some of our experts will complete your request immediately.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>