Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My current set up: mailserver1 mailserver2 (both serving the same domain)

and

user1 user2

I want do redirect all mails which are addressed to user1 to mailserver1 and the same for user2 to mailserver2.

So, I was able to find a lot of tutorials, which describes how to redirect all messages regarding a domain to a different mail server but not for each individual user.

Could someone help me which the configuration?

share|improve this question
add comment

2 Answers

I'm not sure if I correctly understand how both of these servers can serve the same domain. Does your domain have two MX records with the same priority, one for each server, so that the incoming mails are distributed among these two servers?

If you want to redirect mails of a specific account to another address, /etc/aliases would be the way to go. For example, to redirect the mails for the recipient users1 to another address:

user1: anotheraddress@anotherdomain.com

But to redirect the mails to the other mailserver, I assume it would need its own domain. Maybe you can use the IP...?

user1: anotheraddress@<IP of mailserver2>

I'm not really sure how this works because I don't have experience with mail server load balancing, which is what I assume you are doing.


EDIT in response to your comment: I'm still not really sure what you're trying to accomplish.

mail to user@domain arrives at server1 and server1 decides depending on the user@domain if its redirected to mailserver1 or mailserver2. but both mailserver are included in MX record and serves the same domain (no difference)

This seems like contradiction in terms to me. If you specify both mailserver1 and mailserver2 in your MX records, the sending server will choose one of these servers randomly and deliver the mail to this server. Only one of the servers will receive the mail, so any configuration you have in place on mailserver1 will not affect the mail if mailserver2 received it.

furthermore i want to create a mail gateway which redirects a mail to a individual mail server by receiver.

Is it possible that you don't want to redirect the incoming mail to an MTA like Postfix, but instead to an MDA like Cyrus or dovecot that stores the mail in a user mailbox for later retrieval?

http://en.wikipedia.org/wiki/Message_transfer_agent
http://en.wikipedia.org/wiki/Mail_delivery_agent

I can imagine that a setup like this what you are looking for:

          MX  +----+         +----+
        +---->|MTA1|\-------/|MDA1|
        |     +----+ \     / +----+
        |             \   /
+------+|              \ /
|Domain|+               +
+------+|              / \
        |             /   \
        |     +----+ /     \ +----+
        +---->|MTA2|/-------\|MDA1|
          MX  +----+         +----+

It could work like this:

  1. Someone sends a mail to user@domain; the sending server decides randomly to deliver the mail to either MTA1 or MTA2.
  2. MTA1 and MTA2 have the same configuration; there are two MTA just for redundancy reasons. They parse the local part of the recipient mail address and use it to decide to which MDA the mail should be delivered.
  3. The MTA delivers the mail to the MDA, for example via LMTP.
  4. The MTA stores the mail in a mailbox.
  5. Users can now connect to their respective MDA and retrieve the mail, for example via IMAP.
share|improve this answer
    
thanks for your quick response. "does your domain have two MX records with the same priority," thats correct. furthermore i want to create a mail gateway which redirects a mail to a individual mail server by receiver. so its not possible to redirect just to a mail address rather to a mail server. f.e. mail to user@domain arrives at server1 and server1 decides depending on the user@domain if its redirected to mailserver1 or mailserver2. but both mailserver are included in MX record and serves the same domain (no difference) –  Sunny Sep 13 '13 at 21:23
    
"user1: anotheraddress@<IP of mailserver2>" doesnt work, because the mailserver needs the domain name in order to handle the message (at least with exchange server) –  Sunny Sep 13 '13 at 21:29
add comment

Martin's answer is correct.

Configure both mail servers to accept mail for your domain, and for their own unique hostnames.

e.g. if your domain is example.com and your mail servers are mail1.example.com and mail2.example.com then mail1 should accept mail for both example.com and mail1.example.com and mail2 should accept mail for both example.com and mail2.example.com

Note that mail1.example.com and mail2.example.com need to be defined in your DNS or as entries in /etc/hosts on both servers. Presumably, they are already defined in DNS because you have MX records pointing at them.

Entries in /etc/aliases on mail1 would then redirect mail for some users to mail2 - e.g.

user1: user1@mail2.example.com

Similarly, you could also have aliases on mail2 to redirect mail for some users to mail1 - but be careful to avoid creating a mail loop if both servers define aliases for the same address.

Don't forget to run the 'newaliases' command after editing /etc/aliases.

On a more general note, if one of your mail servers is running postfix and the other is running MS Exchange, then hide the Exchange server behind a firewall and make the postfix server your mail gateway. The postfix server should have the sole MX record pointing at it, so all incoming mail goes to it. It then decides whether to deliver inbound mail locally, or forward some of it on to the exchange server.

You almost certainly do not need two MX servers, and having two will likely cause you far more trouble than you think it will solve, especially if one of them is a capable, secure and robust mail server like postfix and the other is Exchange.

For a brief summary of some of the reasons why having a second MX server is usually a mistake, see:

http://serverfault.com/questions/47312/mx-backup-service/47325#47325

That question was specifically about backup (lower priority) MX servers, but the same principles apply - with added complications because (due to DNS round-robin) roughly 50% of incoming mail will go to one server and 50% to the other.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.