Configure Postfix to relay sub-domains

I found myself in need to having Postfix relay or forward an entire sub-domain to a remote server. My setup includes a number of test servers running my development installs of the Freeside Billing system.

The setups need to be able to both send and receive email. Sending is for system email delivery. Receiving is mainly for the built-in Request Tracker ticketing system. I have installed Postfix on a separate web server I am planning on replacing my primary production server.

Let’s get started…

Postfix is an extremely complex and customizable MTA. One of its many function is to provide “transport” for entire domains or individual mailboxes.

Enable transport in Postfix

Edit: /etc/postfix/main.cf Add the following.

transport_maps = hash:/etc/postfix/transport

For each domain or sub-domain you want to relay add the following:

relay_domain = domain.com sub.domain.com sub.sub.domain.com

Create the transport table

Edit/create /etc/postfix/transport Add the following:

domain.com             smtp:127.0.0.1:10025
sub.domain.com         smtp:10.20.20.20:25
sub.sub.domain.com     smtp:192.168.0.101:10025

Hash that file…

Run the following command to create a has table that Postfix can read.

$ sudo postmap /etc/postfix/transport

Restart Postfix

$ sudo systemctl restart postfix

You should be able to tail your maillog file and see mail being relayed.

Be sure to read the main page for transport.

About the Author

Jim Lucas

Owner and proprietor of this establishment

Leave a Reply

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