Redundant Servers and Load Balancing using MX Records

Discussion in 'Mail Gateway: Installation and configuration' started by dietmar, Nov 25, 2005.

  1. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    16,484
    Likes Received:
    314
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. mariagonzalez

    mariagonzalez New Member

    Joined:
    May 21, 2005
    Messages:
    7
    Likes Received:
    0
    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
     
  3. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    16,484
    Likes Received:
    314
    MS Exchange also uses MX records when it sends mail. So you just need to add two MX records for your 'smarthost'.

    - Dietmar
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. mariagonzalez

    mariagonzalez New Member

    Joined:
    May 21, 2005
    Messages:
    7
    Likes Received:
    0
    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
     
  5. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    16,484
    Likes Received:
    314
    yes, that should work.

    - Dietmar
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. JohnKyrle

    JohnKyrle New Member

    Joined:
    Mar 5, 2007
    Messages:
    14
    Likes Received:
    0
    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?
     
  7. tom

    tom Proxmox Staff Member
    Staff Member

    Joined:
    Aug 29, 2006
    Messages:
    13,635
    Likes Received:
    418
    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)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. flameangel81

    flameangel81 New Member

    Joined:
    Jul 8, 2009
    Messages:
    1
    Likes Received:
    0
    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
     
    #8 flameangel81, Jul 8, 2009
    Last edited: Jul 8, 2009
  9. peterwynne

    peterwynne Member

    Joined:
    Jul 5, 2008
    Messages:
    53
    Likes Received:
    0
    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.
     
  10. tom

    tom Proxmox Staff Member
    Staff Member

    Joined:
    Aug 29, 2006
    Messages:
    13,635
    Likes Received:
    418
    see http://www.proxmox.com/cms_proxmox/en/technology/proxmox-ha-cluster/multiple-address-records/
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    16,484
    Likes Received:
    314
    That depends on the MTA you use. Proxmox uses postfix, and postfix supports that.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. peterwynne

    peterwynne Member

    Joined:
    Jul 5, 2008
    Messages:
    53
    Likes Received:
    0
    thanks for that, could you explain in a bit more detail?
     
  13. guletz

    guletz Active Member

    Joined:
    Apr 19, 2017
    Messages:
    929
    Likes Received:
    124
    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
     
  14. Walhalla

    Walhalla Member

    Joined:
    Jan 26, 2018
    Messages:
    36
    Likes Received:
    2
    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.
     
  15. Walhalla

    Walhalla Member

    Joined:
    Jan 26, 2018
    Messages:
    36
    Likes Received:
    2
  16. Juliano Silva

    Juliano Silva Member

    Joined:
    Oct 15, 2017
    Messages:
    164
    Likes Received:
    0
    > 404 Page not found
     
  17. DerDanilo

    DerDanilo Member
    Proxmox Subscriber

    Joined:
    Jan 21, 2017
    Messages:
    266
    Likes Received:
    24
  18. tom

    tom Proxmox Staff Member
    Staff Member

    Joined:
    Aug 29, 2006
    Messages:
    13,635
    Likes Received:
    418
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice