Skip to Main Content

Configure a CentOS 6.4 Web Server on Rackspace - Part 5: Postfix Email Forwarding

Postfix is the default mailserver on CentOS. The following tutorial will set up email forwarding for the domains on our server. We will assume that the primary domain on the server is called

DNS Settings

1. Create an A record for the mailserver, e.g.

2. Add an MX record to any hosted domains (e.g. pointing to with priority 10.

3. Use dig to check the settings (look at ANSWER SECTION)

$ dig

$ dig mx


Next, use the GUI to open the SMTP port (port 25) so we can receive connections:

$ sudo system-config-firewall-tui
# open the port for SMTP
$ sudo service iptables restart

We can check the settings:

$ sudo iptables -L
# output should contain the line:
# ACCEPT tcp -- anywhere anywhere tcp dpt:smtp


Start Postfix:

$ sudo service postfix start
$ sudo chkconfig postfix on

Open the Postfix config file

$ sudo vim /etc/postfix/

Uncomment or add the following lines:

inet_interfaces = all

relay_domains =

mynetworks =,

myhostname =

Finally, add virtual_alias_domains, which is a list of your hosted domains. And add virtual_alias_maps, which is a file that will hold the forwarder-to-address mappings. I'd like a better way to handle this, like we did with mass virtual hosts in httpd.conf, but I haven't had time to figure one out yet:

virtual_alias_domains =,
virtual_alias_maps = hash:/etc/postfix/virtual

Then open the virtual file:

$ sudo vim /etc/postfix/virtual

And add each email forwarder:
# optionally, add a catch-all address for the domain

The virtual file could also be built from a database if that suits you needs better.

Finally, reload postfix settings:

# rebuild the forwarder database
$ sudo postmap /etc/postfix/virtual
# restart postfix
$ sudo service postfix restart

Make sure we can connect on port 25:

$ telnet 25
220 ESMTP Postfix
# Press CTRL + ]
telnet > quit 

The email forwarders we created in the virtual file should be working now. Note that the DNS settings at the beginning of the tutorial will take efect in about 5 minutes if your DNS is hosted at Rackspace. Some other DNS providers can take up to 48 hours.


One problem with forwarding mail is that your server's IP address reputation will be harmed by forwarding spam messages. Gmail recommends tagging spam using SpamAssassin.


Most RecentRSS


March 2016 (1)
January 2016 (1)
September 2015 (1)
May 2015 (1)
April 2015 (1)
March 2015 (1)
February 2015 (2)
January 2015 (5)
September 2014 (2)
August 2014 (4)
July 2014 (1)
March 2014 (1)
November 2013 (3)
September 2013 (3)
July 2013 (6)
June 2013 (1)
May 2013 (1)
March 2013 (2)
February 2013 (3)
January 2013 (4)