Redundant Servers and Load Balancing using MX Records

dietmar

Proxmox Staff Member
Staff member
Apr 28, 2005
17,262
667
213
Austria
www.proxmox.com
Redundant Servers and Load Balancing using MX Records

The normal mail delivery process looks up DNS Mail Exchange (MX) records to determine the destination host. A MX record tells the sending system where to deliver mail for a certain domain. It is also possible to have several MX records for a single domain, they can have different priorities. For example, our MX record looks like that:

Code:
> dig -t mx proxmox.com

;; ANSWER SECTION:
proxmox.com.            22879   IN      MX      10 mail.proxmox.com.

;; ADDITIONAL SECTION:
mail.proxmox.com.       22879   IN      A       213.129.239.114

Please notice that there is one single MX record for the Domain proxmox.com, pointing to mail.proxmox.com. The 'dig' command automatically puts out the corresponding address record if it exists. In our case it points to "213.129.239.114". The priority of our MX record is set to 10 (preferred default value).

Hot Standby with backup MX Records

Many people do not want to install two redundant mail proxies, instead they use the mail proxy of their ISP as fallback. This is simply done by adding an additional MX Record with a lower priority (higher number). With the example above this looks like that:

Code:
proxmox.com.            22879   IN      MX      100 mail.provider.tld.

Sure, your provider must accept mails for your domain and forward received mails to you.

You will never lose mails with such a setup, because the sending Mail Transport Agent (MTA) will simply deliver the mail to the backup server (mail.provider.tld) if the primary server (mail.proxmox.com) is not available.

Load Balancing wit MX Records

Using your ISPs mail server is not always a good idea, because many ISPs do not use advanced spam prevention techniques like greylisting. It is often better to run a second server yourself to avoid lower spam detection rates.

Anyways, it's quite simple to set up a high performance load balanced mail cluster using MX records. You just need to define two MX records with the same priority. I will explain this using a complete example to make it clearer.

First, you need to have 2 working proxmox mail gateways (mail1.example.com and mail2.example.com), each having its own IP address (the rest of the setting should be more or less equal, i.e. you can use backup/restore to copy the rules). Let us assume the following addresses (DNS address records):

Code:
mail1.example.com.       22879   IN      A       1.2.3.4
mail2.example.com.       22879   IN      A       1.2.3.5

Btw, it is always a good idea to add reverse lookup entries (PTR records) for those hosts. Many email systems nowadays reject mails from hosts without valid PTR records. Then you need to define your MX records:

Code:
example.com.            22879   IN      MX      10 mail1.example.com.
example.com.            22879   IN      MX      10 mail2.example.com.

This is all you need. You will receive mails on both hosts, more or less load balanced. If one host fails the other is used.

Other ways

Multiple Address Records: Using several DNS MX record is sometime clumsy if you have many domains. It is also possible to use one MX record per domain, but multiple address records:

Code:
example.com.            22879   IN      MX      10 mail.example.com.
mail.example.com.       22879   IN      A       1.2.3.4
mail.example.com.       22879   IN      A       1.2.3.5

Using Firewall features: Many firewalls can do some kind of RR-Scheduling when using DNAT. See your firewall manual for more details.
 
does this also work for outgoing

hi,

good information, worked perfect on my environment.
but how can i configure my mailserver (exchange 2003) to load balance the outgoing traffic also?

my system:
I have two proxmox mail gateways, loadbalancing with mx records.
the exchange sends all outgoing messages (smarthost) just to one proxmox. how can i set this up redundant?

any help is welcome,
maria
 
MS Exchange also uses MX records when it sends mail. So you just need to add two MX records for your 'smarthost'.

- Dietmar
 
just to be clear:

i configured my exchange to forward all to proxmox.mydomain.com (smarthost).

in my windows DNS i have now the following hosts:

proxmox-first.mydomain.com 192.168.2.100
proxmox-backup.mydomain.com 192.168.2.101

and 2 mx records:

1. proxmox.mydomain.com pointing to proxmox-first.mydomain.com - priority 10
2. proxmox.mydomain.com pointing to proxmox-backup.mydomain.com - priority 10

seems working.
can you review my settings?

thanks,
maria
 
I would assume that if you are running more that 1 proxmox unit for load balancing and failover then you need one licence for each unit, is that correct?
 
I would assume that if you are running more that 1 proxmox unit for load balancing and failover then you need one licence for each unit, is that correct?

hi,
yes, you are right. proxmox license per mail domain and per machine.

you can do simple loadbalancing like described above, or if you need high availablity with synchronized data and management you should to to the Proxmox HA cluster (also licensed per machine, so you need at least two cluster licenses)
 
Hi there,

I urgently need some help for my dns configuration.

We are currently moving from our one exchange towards a hosted solution.

I need to know how i shall proceed to receive mail at both location ill i completely place my exchange server out of commission.

The following are the configurations am planning to do.
1.2.3.4 (Fixed IP address of web server) is my current web server where my web site is hosted.
1.2.3.5 (Fixed IP address of my Exchange server where my current mail server lies)

2.3.4.5 Fixed IP address where the hosted mail server resides.
mydomain.com A 1.2.3.4 1 00:00
mail.mydomain.com A 1.2.3.5 1 00:00
webmail.mydomain.com A 2.3.4.5 0 08:00
mydomain.com MX mail.mydomain.com (Priority 10) 1 00:00
mydomain.com MX webmail.mydomain.com (Priority 10) 1 00:00

Where mail.mydomain.com are my current settings and webmail.mydomain.com will be the new hosted server
Please let me know if this will work thanks
 
Last edited:
if someone was to use the multiple DNS record method so that 2 connections [IPs] share the same record does that offer fault tolerance?

IP1 - proxhostname.mydomain.com
IP2 - proxhostname.mydomain.com

If IP1 is down - will a sender automatically try on IP2?

I know with MX records this sort of fault tolerance is possible, just wondered if it was with multiple address records.
 
if someone was to use the multiple DNS record method so that 2 connections [IPs] share the same record does that offer fault tolerance?

IP1 - proxhostname.mydomain.com
IP2 - proxhostname.mydomain.com

If IP1 is down - will a sender automatically try on IP2?

I know with MX records this sort of fault tolerance is possible, just wondered if it was with multiple address records.

see http://www.proxmox.com/cms_proxmox/en/technology/proxmox-ha-cluster/multiple-address-records/
 
Hi @dietmar,

Your small howto need some clarifications, like this:

1. For incoming mails, usually is not a problem in case of your only MX mailserver is down, because any mailserver will try to deliver the mail for at least 48 hours / 2 days. So it is a lot of time to repair your broken MX mailserver. When your mailsever will be online again, then in a few hours, you will start to recevie the mails that was not delivered by others mailserver.

2. For the case when you use 2 different MX mailserveres:
- you will need to use some kind of shared storage(could be many variants) for users INBOX, so if a mail are receive by the MX1 then you must be able to see the same mail also in the MX2
 
2. For the case when you use 2 different MX mailserveres:
- you will need to use some kind of shared storage(could be many variants) for users INBOX, so if a mail are receive by the MX1 then you must be able to see the same mail also in the MX2

But PMG is a "gateway". Doesnt store users emails - "only" checks and forwards to the final machine where the mails are stored. This machine is not the MX.
 
Situation: multiple PMG servers configured in MX with equal preference:

abc.com IN MX 10 pmg1.abc.com
abc.com IN MX 10 pmg2.abc.com
abc.com IN MX 10 pmg3.abc.com

Greylisting is enabled.

Remote server tries to deliver mail for abc.com:

- connects to pmg1 - pmg1 whitelists and defers the email

- after retry interval elapses, remote server re-tries, but this time it connects to pmg2 and since this is "new", it's deferred for greylisting

- remove server retries a third time after its second retry interval expires - and this time connects to pmg3 ... and it's greylisted again.


The next time the remote server attempts the send, the attempt should succeed, since now all 3 PMG servers at abc.com should have the (senderIP, sender-email, recipient-email) triple - unless the mail retry is now so long that those entries have expired. Even if the mail gets delivered, depending on the retry intervals, the mail could by now be seriously delayed.

Is there a solution to this problem, other than disabling greylisting in PMG?
 
hi,
yes, you are right. proxmox license per mail domain and per machine.

you can do simple loadbalancing like described above, or if you need high availablity with synchronized data and management you should to to the Proxmox HA cluster (also licensed per machine, so you need at least two cluster licenses)
Why is it necessary to get a separate license for each server even though the servers are already running synchronized with each other?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!