Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Have some troubles with internal mail server and wanting to migrate to external mail provider (

I know how to transfer users and their mail (many thanks for API to Yandex), but in current configuration we have one host as pop3/smtp/imap server ( and now we need to work with three different servers - pop/smtp/

The main question is how to transparently transfer incoming user requests from to, and depending on port of connection.

Any ideas? Thanks.

share|improve this question
What do you have to work with? Can you just forward traffic to the appropriate destination using netfilter as a temporary workaround and migrate users' configurations to the new server names over time? – the-wabbit Feb 10 '13 at 15:42
Yes, i think i can. Thanks. – alekseygr Feb 10 '13 at 18:00
up vote 0 down vote accepted

You put put a machine at that relays traffic on the POP3 port to, the IMAP4 port to, and so on.

Turn on IP forwarding (otherwise the kernel will drop redirected packets):

echo 1 >/proc/sys/net/ipv4/ip_forward

Relay port 110 to

iptables -t nat -A PREROUTING -p tcp --dport 110 -j DNAT --to-destination
iptables -t nat -A POSTROUTING -p tcp -d W --dport 110 -j MASQUERADE

There are a number of problems with this:

  1. You now have a new machine you have to maintain.
  2. The bandwidth to this host is 2x the bandwidth to Yandex's servers. That may be a lot!
  3. You have a single point of failure.
  4. If Yandex changes their IP address (or uses multiple IPs) you will always be chasing Yandex.

If I were to use this technique, I would only use it to find users that haven't changed their configuration yet. Keep good logs of which IP addresses use this service and make sure you track these people down and configure their machines correctly as soon as possible.

I do not recommend using this technique as a permanent solution. If you are so overloaded that your "temporary" solutions often turn into permanent solutions, do not do this at all. Instead, let people be without email for a while as you visit each machine to configure it properly. If Yandex has a web-mail option, they can use that while they wait. Reconfiguring the clients is something that could be automated with PowerShell; you shouldn't actually visit each machine.

For a new configuration, you might consider using hostnames like and Make those CNAMEs to the Yandex servers. If you have a very large company, you might consider creating a CNAME for each user so that is a CNAME that can be pointed at any particular server. In the future you'll be able to move users one at a time.

share|improve this answer
Thanks for your solution. I will think about using it as temporary, before all of my users don't change their client configurations. – alekseygr Feb 10 '13 at 18:05

Your Answer


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.