• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Setup Mail Forwarding in Postfix

Written by Rahul, Updated on January 5, 2016

Postfix is widely used Mail Transfer Agent (MTA) server, which provides to send, receive and forward emails over network. This tutorial will help you to configure your Postfix server to forward emails.

Install Postfix MTA

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

On Debian Based Systems

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

On RHEL Based Systems

# yum install postfix

On OpenSUSE Systems

# zypper in postfix

After installation make sure Postfix is running on your system. Default postfix used standard port 25. Use the following commands to check that your system is listening on port 25 or not.

# netstat -tulpn | grep 25

tcp    0   0 0.0.0.0:25    0.0.0.0:*         LISTEN      4398/master
tcp6   0   0 :::25         :::*              LISTEN      4398/master

Configure Email Forwarding in Postfix

Let’s start with email forwarding configuration in Postfix configuration file (/etc/postfix/main.cf). Edit this file and add/edit the following configurations. Change example.com and example.net domain names with your domain name

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

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

Email Forwarding Examples

/etc/postfix/virtual is the file where we will add email forwarding rules. Let’s starts begin with the email forwarding rules.

1 – Forward all emails sent to [email protected] and [email protected] to [email protected]

[email protected] [email protected]
[email protected] [email protected]

2 – Forward [email protected] emails to [email protected] and [email protected]

[email protected] [email protected] [email protected]

3 – Forward any email sent to @example.com domain to [email protected] Also forward any email sent to @example.net domain to [email protected] as well as [email protected]

@example.com [email protected]
@example.net [email protected] [email protected]

Verify Setup

Let’s verify all settings by sending emails to @example.com and @example.net domain email accounts.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

3 Comments

  1. Avatar Elio Reply
    July 12, 2019 at 11:41 pm

    Thanks this works well

    BUT…

    When make forwarder to another email via gmail relayhost, it does not show the name of the email from the original sender, it shows the name of my host configured in google
    example:
    relayhost = [smtp.gmail.com]:587

    From mail sender([email protected]) To destiny([email protected])
    forwaring another mail ([email protected])

    When arrive el mail to [email protected] through forwarding
    It does not show the mail of the sender [email protected]
    Show the sender’s mail using to do the relayhost example [email protected]

    Please helpe

  2. Avatar amargujeti Reply
    June 13, 2019 at 10:06 am

    hi rahul

    i have stuck in postfix

    i have an private client ( 10.0.21.16 ) and Non -DMZ server ( 10.92.101.4) and DMZ server ( 10.92.103.1)

    first i relayed my 10.0.21.16 mails to NON- DMZ

    from Non -DMZ i have routed to DMZ

    Now from DMZ i want to send (relay or route) to public domains ?

    Note : i have bought public domain for DMZ server , my both client and Non – DMZ server have local domain which is using by inserting local domain in /etc/hosts

  3. Avatar georgemr Reply
    February 3, 2017 at 5:19 pm

    In order for this to work, after the creation of file /etc/postfix/virtual with the forwarding rules and before reloading the postfix service with postix reload, the following should be executed: postmap /etc/postfix/virtual.

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy