Configure Postfix as mail forwarding on Ubuntu/Debian

Postfix is a popular mail transfer agent (MTA) used to handle email forwarding, among other tasks. To set up email forwarding using Postfix, you’ll need access to a Unix-like server where Postfix is installed and configured. Here are the steps to set up email forwarding using Postfix:

  1. Install Postfix (if not already installed):
    Ensure Postfix is installed on your server. You can install it using a package manager like apt on Ubuntu or yum on CentOS:

    # For Ubuntu/Debian
    sudo apt-get install postfix
    # For CentOS
    sudo yum install postfix
  2. Configure Postfix:
    Postfix’s configuration files are usually found in the /etc/postfix/ directory. You’ll need to modify the file to enable forwarding. Open the file in a text editor:

    sudo nano /etc/postfix/

    Add or modify the following lines to enable forwarding:

    virtual_alias_domains =  # Replace with your domain
    virtual_alias_maps = hash:/etc/postfix/virtual

    Replace with your actual domain name.

  3. Create a Virtual Alias Map:
    Create the /etc/postfix/virtual file to specify the forwarding rules. Each forwarding rule should be in the format:

    For example, to forward emails from to, add this line to /etc/postfix/virtual:
  4. Generate the Virtual Alias Database:
    After adding your forwarding rules, you need to generate the database file:

    sudo postmap /etc/postfix/virtual
  5. Restart Postfix:
    Restart the Postfix service to apply the changes:

    sudo systemctl restart postfix
  6. Test the Forwarding:
    Send an email to the source email address ( in the example). It should be forwarded to the destination address (

  7. Check with the postconf command that the domain aliases and alias file have been setup properly.

    $ postconf -n | grep virtual
    virtual_alias_domains =
    virtual_alias_maps = hash:/etc/postfix/virtual

Remember to replace,, and with your actual domain and email addresses.

Additionally, make sure your server’s DNS records (MX and A/AAAA) are correctly set up to handle email for your domain. This setup assumes you have administrative access to the server and can modify Postfix configuration files.

Copyright © 2013-present All rights reserved.