Tuesday 19 March 2013

How to set a Postfix SMTP mail Gateway

How to set a Postfix SMTP mail Gateway

Few months ago when I started the implementation of a big system in one of our Data Centers.
It became clear we need a server to act a mail HUB for all servers within the same network.
This was a secure environment and emails had to be cetralised and logged.

I would like to draw your attention for something imporatnt; we have an Exchange server in the office and all emails must be archived for a long period of time.

So emails are sent from clients within the Data Centre through the Postfix SMTP Gateway and from the SMTP Gateway, emails are forwarded to our Exchange in the office.

I chose Postfix for the task because I think it is easy to setup, robust and secure.

There are only two files you need to touch, which are:
/etc/postfix/main.cf
/etc/postfix/transport

I will give you details of my setup and network below.
Network: 10.10.10.0/24
SMTP Gateway IP: 10.10.10.224
Exchange Server Name: mail.domain.com
Exchange Server IP: Public IP for Exchange

Server Side
Edit /etc/postfix/transport file
# cd /etc/postfix
# vi transport

Go to the bottom of the file and add the following line:
mail.domain.com :[Public IP Address of our Exchange Server]

Creating transport.db
# postmap transport

The command above will create the file /etc/postfix/transport.db

Now we need to edit the /etc/postfix/main.cf    
# vi mail.cf

Comment out the line
#inet_interfaces = localhost (make sure it has a # at the beggining of the line)

Uncomment the line below
inet_interfaces = all (remove the # from the begging of this line)

Modify the line below:
mynetworks = 127.0.0.0/8 10.10.10.0/24 (this is your network which)

Restart Postfix process
# service postfix restart

That is it. Your SMTP Gateway is ready to receive emails from the server clients on your network.

Client Side:
# cd /etc/postfix
# vi transport

add the line below to the file and save it
smtpgateway.domain.com :[10.10.10.224]

Create the transport.db file
# postmap transport

Now we need to edit the /etc/postfix/main.cf
# vi mail.cf

Make sure the line below is uncommented
inet_interfaces = localhost
Note: this is a client, therefore for security reasons the SMTP service only needs to answer to the localhost.

Add the line below
relayhost = [10.10.10.224]

Make sute the lines below are uncommented
alias_maps = hash:/etc/aliase
alias_database = hash:/etc/aliases

Restart Postfix process
# service postfix restart


Repeat the Client Side Process on all clients which nees sending email via the SMTP Gateway.

That is it Folks, I hopw you enjoy these simple How Tos

by Renato de Oliveira



1 comment:

  1. Dear Renato,

    Very interesting post, please find bellow a configuration that I want to implement, I don't know if it's OK or not, any advise will be very appreciated:

    Exchange 2013 (Mail Box and CAS role on the same HW) <---> FireWall <---> Postfix SMTP mail Gateway.

    What confused me is the client and server side configuration to do, can you please advise.

    Kind Regards,

    ReplyDelete