How to Setup Mail Forwarding in Postfix Linux

Postfix is a commonly used MTA (Mail Transfer Agent) program that can receive, deliver or route emails. Postfix can be configured as mail forwarding domains server using virtual_alias_maps settings. The main purpose is to forward mail elsewhere. So this article shows how to setup mail forwarding on a Linux server using the postfix program.

Mail Forwarding

Install Postfix MTA

We are assuming that you have already postfix installed and configured on your system. Or you can use following commands to install Postfix on Linux.

For CentOS/RHEL Systems

# yum install postfix

For Ubuntu/Debian Systems

$ sudo apt-get update
$ sudo apt-get install postfix

For OpenSUSE Systems

# zypper in postfix

Start Postfix MTA and Verify Installation

Use follwoing command to start the Postfix MTA service.
For CentOS/RHEL and OpenSUSE Systems

# chkconfig postfix on
# service postfix start

For Ubuntu/Debian Systems

$ sudo chkconfig postfix on
$ sudo service postfix start

By default postfix used port 25. Now verify that Postfix service is running on your system or not.

# netstat -tulpn | grep 25
tcp    0   0 0.0.0.0:25    0.0.0.0:*         LISTEN      5379/master
tcp6   0   0 :::25         :::*              LISTEN      5379/master

Configure Email Forwarding in Postfix

Now configuring postfix to forward mails. Edit Postfix configuration file add change techoism.com and techoism.net domain names with your domain name.

# vim /etc/postfix/main.cf

Add the following content:

virtual_alias_domains = techoism.com techoism.net
virtual_alias_maps = hash:/etc/postfix/virtual

After making changes in configuration files make sure to restart Postfix service.

Email Forwarding Examples

Now we will add rules to forward emails to other email I’d. Let’s starts begin with the email forwarding rules. We will add rules in “/etc/postfix/virtual” file.

# vim /etc/postfix/virtual

1) Now we will add rule to forward emails to anuketjain@youremail.com email account.

support@techoism.com anuketjain@youremail.com
support@techoism.net anuketjain@youremail.com

Above rule will forward all sent emails to support@techoism.com & support@techoism.net to anuketjain@youremail.com account.

2) Now we will add rule to forward emails to anuketjain@youremail.com and administrator@youremail.com.

support@techoism.com anuketjain@youremail.com administrator@youremail.com

Above rule will forward all sent emails to support@techoism.com to anuketjain@youremail.com and administrator@youremail.com accounts.

3) Now we will add rules to forward all domain email to any other emails.

@techoism.com anuketjain@youremail.com administrator@youremail.com
@techoism.net anuketjain@youremail.com

Above rule will forward any email sent to @techoism.com domain to anuketjain@youremail.com as well as administrator@youremail.com. Also forward any email sent to @techoism.net domain to anuketjain@youremail.com

Update Postfix Lookup Table

After entering the forwarding rules, run the following commands for the new settings to take effect.
For CentOS/RHEL and OpenSUSE Systems

# postmap /etc/postfix/virtual
# service postfix reload

For Ubuntu/Debian Systems

$ sudo postmap /etc/postfix/virtual
$ sudo service postfix reload

Test it now

Now try sending an email to the address on your domain, and you should see the same mail forwarded to other email account.

Enjoy it!

No Responses

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.