Postfix Email Forwarding on Ubuntu (18.04–24.04) – Complete Setup Guide

Configure Postfix Email Forwarding on Ubuntu 18.04 / 20.04 / 22.04 / 24.04

This guide shows you how to forward emails like email@yourdomain.com to any other inbox such as email@forwardingaddress.com using Postfix on Ubuntu 18.04, 20.04, 22.04 or 24.04. Works for both Nginx and Apache servers.

I use DigitalOcean to host almost all of my WordPress sites on Nginx for performance and reliability. Postfix configuration works exactly the same on both Nginx and Apache servers, and once set up, it allows any address at your domain to forward to any external email address.

When you finish, any email sent to anything@yourdomain.com can be forwarded to your main inbox (Gmail, Outlook, etc.).

Step 1 – Install Postfix

Choose your Ubuntu version below (commands are identical):

Ubuntu 18.04

sudo apt update
sudo apt install postfix -y

Ubuntu 20.04

sudo apt update
sudo apt install postfix -y

Ubuntu 22.04

sudo apt update
sudo apt install postfix -y

Ubuntu 24.04

sudo apt update
sudo apt install postfix -y
When prompted, choose Internet Site and enter your domain: yourdomain.com.

Step 2 – Configure DNS Records

You need two DNS entries:

  • A Record: mail.yourdomain.com → your server IP
  • MX Record: yourdomain.commail.yourdomain.com
Correct DNS A + MX settings
DNS may take 5–15 minutes to propagate.

Step 3 – Edit Postfix Main Configuration

Open the main Postfix config:

sudo nano /etc/postfix/main.cf

Add these lines directly **below**:

alias_database = hash:/etc/aliases
virtual_alias_domains = yourdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual

Ensure your domain is listed in mydestination:

mydestination = $myhostname, localhost, yourdomain.com
Correct main.cf configuration example

Step 4 – Create the Virtual Alias File

Open/create your alias file:

sudo nano /etc/postfix/virtual

Forward a single address:

email@yourdomain.com    email@forwardingaddress.com

Forward all (catch-all):

@yourdomain.com         email@forwardingaddress.com

Step 5 – Open Port 25

Allow incoming SMTP mail:

sudo ufw allow 25

Step 6 – Map Aliases & Reload Postfix

sudo postmap /etc/postfix/virtual
sudo systemctl reload postfix

Step 7 – Test Your Forwarding

Send an email from a different address to:

email@yourdomain.com

Check that it arrives in:

email@forwardingaddress.com
  • Do NOT send the test from the same address you're forwarding to.
  • If there are issues, check logs:
    sudo tail -f /var/log/mail.log

Extra Tips

Multiple aliases:

info@yourdomain.com     email@forwardingaddress.com
support@yourdomain.com  email@forwardingaddress.com

Forward to multiple recipients:

email@yourdomain.com    one@address.com, two@address.com

Get $200 Free DigitalOcean Credit

Remember, if you don't already have a DigitalOcean account, you can get $200 free credit using my referral link below:

👉 Click here to claim $200 DigitalOcean credit

I use DigitalOcean for nearly all of my WordPress and Nginx servers, including the exact setup shown in this guide. It's fast, reliable, and perfect for running Postfix email forwarding.

Scroll to Top