habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Easy Install Postfix Ubuntu 20.04

2 min read


Hi Dude, today i will post simple article about install postfix Ubuntu 20.04. Ok lets go. Postfix is open source mail transport agent with many feature.

#1. Setup Hostname Server

In this server, im using server name smtp.habibza.in. Just run simply command like this.

hostnamectl set-hostname smtp.habibza.in

After that, jump to /etc/hosts and edit

#vim /etc/host localhost smtp.habibza.in smtp

Reboot for a while to make sure the host has changed perfectly.

#2. Install Postfix in Ubuntu 20.04

In ubuntu server, run the following command below.

sudo apt-get update
sudo apt-get install postfix -y

By default, will appear conversation below. We will be asked to select a type for mail configuration. Select “Internet Site”.

Install Postfix Ubuntu 20
  • No configuration: The installation process will not configure any parameters.
  • Internet Site: Setup Postfix for sending emails to other MTAs and receiving email from other MTAs.
  • Internet with smarthost: Setup postfix to receive email from other MTAs, but using another smart host to relay emails to the recipient.
  • Satellite system: Setup smart host for sending and receiving email.
  • Local only: Setup emails are transmitted only between local user accounts.

Press OK. Input hostname full FQDN.

Input Server Hostname

After finish installed, Postfix will be automatically started and a /etc/postfix/main.cf file will be generated.

See also  Zimbra Set COS (class of service) All User

#3.Check status Postfix.

systemctl status postfix

Check binary postfix installed.

dpkg -L postfix | grep /usr/sbin/



#4. Check Allow TCP Port 25 (inbound) in Firewall.

We have to open port 25 TCP incoming in firewall. (If we activated firewall UFW in server).

sudo ufw allow 25/tcp

#5. Check Port 25 Outbound.

Simply way to check port 25 outbound is using telnet. We use telnet port 25 to other server mail, like google gmail mx.

sudo apt install telnet
telnet gmail-smtp-in.l.google.com 25

If it’s not blocked, you would see messages like below.

Connected to gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP y22si1641751pll.208 - gsmtp

If port 25 (outbound) is blocked or something worng, you would see something like:

Trying 2607:f8b0:400e:c06::1a...
telnet: Unable to connect to remote host: Connection timed out.

#6. Setting Postfix and Tune it.

By default, Postfix SMTP server uses the OS’s hostname.

Find the myhostname parameter and set mail.yourdomain.com as the value. It’s not recommended to use the apex domain yourdomain.com as myhostname.

myhostname = smtp.habibza.in
sudo systemctl restart postfix

#7. Creating Email Alias.

sudo nano /etc/aliases

By default, there are only two lines in this file.

# See man 5 aliases for format
postmaster: root

The first line is a comment. Normally we don’t use the root email address. So you can add the following line. Replace username with your real username.

root:   username

This way, emails for [email protected] will be delivered to [email protected]. Now you can save and close the file. Then rebuild the alias database with the newaliases command

sudo newaliases

#8. Using IPv4 Only

By default, Postfix uses both IPv4 and IPv6 protocols, as can been seen with:

postconf inet_protocols


inet_protocols = all

If your mail server doesn’t have a public IPv6 address, it’s better to disable IPv6 in Postfix to prevent unnecessary IPv6 connections. Simply run the following command to disable IPv6 in Postfix.

sudo postconf -e "inet_protocols = ipv4"

Then restart Postfix.

sudo systemctl restart postfix

#9. Increase Attachment Size Limit

By default, the attachment cannot be larger than 10MB, which is indicated by the message_size_limit parameter.

postconf | grep message_size_limit


message_size_limit = 10240000

This parameter defines the size limit for emails originating from your own mail server and for emails coming to your mail server.

See also  PFlogsumm - Daily Report Postfix Monitoring on CentOS 6

To allow attachment of 50MB in size, run the following command.

sudo postconf -e message_size_limit=52428800

message_size_limit=52428800 thats mean maximum size of email is 50 mb.

#10. Setting Postfix Not Open Relay.

This important part setting postfix. We have to make sure sure that our setting Postfix is not open relay.

Just edit /etc/postfix/main.cf and find mynetworks.

vim /etc/postfix/main.cf

See default mynetworks.

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

Change to:

mynetworks =,,

Where, is IP that allow to using this server to sent email.

That is step by step install postfix Ubuntu 20.04 and tuning deployment in Ubuntu. Please feel free for comment. Maybe usefull.

habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Easy Create Laravel Project with Composer

Requirement Laravel, a popular PHP framework, is renowned for its elegant syntax and robust features, making it a top choice for web developers. One...
1 min read

Virtualbox Change Storage Size

Changing the storage size of a virtual machine in VirtualBox involves a few steps. Here’s a general guide. Backup your Virtual Machine (VM) Before...
35 sec read

Easy Setup Logrotate Nginx Ubuntu

Log rotation is an important aspect of managing log files on a Linux system, including those generated by Nginx. Logrotate is a utility that...
1 min read

Leave a Reply

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

Never miss good article from us, get weekly updates in your inbox