Thursday, 14 May 2015

Configure Postfix as a Gateway for Exchange

In this tutorial, we will configure Postfix as a Mail Gateway for a backend Exchange Server or any other back-end mail server. This configuration provides several advantages such as blocking unwanted traffic, virus-scanning ,spam prevention, reduce load on back-end. 

We will configure a Mail Gateway on 'meru.mycompany.com', so that it relays mail for the domain 'mycompany.com' to a mail server on the internal network 'server1.mycompany.com'


1) Edit the file '/etc/postfix/main.cf'. Make the following changes

    myhostname = meru.mycompany.com
    mydomain = mycompany.com


    #the default domain name to append if @domain is missing
    myorigin = $mydomain

    # the network interface addresses on which to receive incoming mail.
    inet_interfaces = all
    # remember to comment this line
    #inet_interfaces = localhost

    #this machine is not the final destination for any domain
    mydestination = 

   #turn off local recipient checking
   local_recipient_maps =



    #Trusted SMTP clients - can relay mail through this server.  
   mynetworks = 192.168.122.0/24, 127.0.0.0/8

    # Relay mail for the domains listed below
    relay_domains = mycompany.com

    # Accept mail only for relay users listed in relay_recipients file
    relay_recipient_maps = hash:/etc/postfix/relay_recipients

    # Where to relay mail
    transport_maps = hash:/etc/postfix/transport


2) Create the file  '/etc/postfix/relay_recipients' containing the list of mail recipients for the domain 'mycompany.com'
shabbir@mycompany.com    x
ali@mycompany.com            x
batul@mycompany.com        x


3) Recreate the relay map
[root@meru ~]# postmap /etc/postfix/relay_recipients

4) Edit the file '/etc/postfix/transport' and add the name of the back-end mail server to which to relay mail for the domain 'mycompany.com'.
mycompany.com  smtp:[server1.mycompany.com]

5) Recreate the transport map.
[root@meru ~]# postmap /etc/postfix/transport

6) To view the parameters changed run the following command.
     postconf -n

7) To check for systax errors, run the following command.
     postfix check

8) Open firewall port 25/TCP.
    firewall-cmd --zone=public --add-service=smtp --permanent
    firewall-cmd --reload

9) Restart postfix service
    systemctl restart postfix


No comments:

Post a Comment