Alias and Virtual Domains with Postfix

Today I ran into the case, that I have my ubuntu server with postfix running as MTA. Since there is no IMAP server or something like this installed, I use this server only for relaying/proxying the mails to my gmail account.

Setup was straight forward (choose "Internet Site" and enter the ip of the server when it asks for mynetworks):

# apt-get install postfix

The /etc/aliases looks like this:

root: carl@dracoblue.net

if I want to send all mails from root to the mail address carl@dracoblue.net.

This all went well, as long as there was only one domain running on the server. Let's say the first domain was example.org and the second one is example.net.

That's why I had to reconfigure the postfix program:

# dpkg-reconfigure postfix

When it asked for the local servers (mynetworks in main.cf) I added example.net at the end.

Now I want that abuse@example.net and hostmaster@example.net mails, will be received by bob@dracoblue.net. Additionally everything to info@example.net will be send to alice@dracoblue.net.

But to make everything working (like Jem explained), I had to modify /etc/aliases and create + modify the /etc/postfix/virtual file.

First of all we need some virtual mapping for the email accounts to local aliases in /etc/postfix/virtual (create it if it does not exist, yet):

example.net this-text-is-not-important
abuse@example.net bob-dracoblue-net
hostmaster@example.net bob-dracoblue-net
info@example.net alice-dracoblue-net

To enable virtual aliases add/change the line to /etc/postfix/main.cf:

virtual_alias_maps = hash:/etc/postfix/virtual

Update the postfix table map for the virtual file with:

# postmap /etc/postfix/virtual

Then the local aliases need to be mapped to real email addresses (append to /etc/aliases:

alice-dracoblue-net: alice@dracoblue.net
bob-dracoblue-net: bob@dracoblue.net

To reload the aliases run:

# newaliases

Eventually you have to run:

# postfix reload

to finalize the setup.

Check /var/log/system.log with:

# tail -f /var/log/system.log

and try to send/receive mails! Have fun!

In open source, postfix, ubuntu by @ 30 Dec 2013

comments powered by Disqus

Recent Files


Recent Dev-Articles

Read recently