Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I want to redirect all mail traffic (localhost port 25) to another server to send mail. Should I use BIND, iptables or some other tool? How would I do this?

share|improve this question
up vote 1 down vote accepted

"BIND" in your question is confusing :). If you are trying to providing web service from one server and mail service from another server, all you need to do is to point the A record of your Mail Exchanger domain to the second server IP(mail server IP). There is no need to load the first server(web server) with your mail traffic. So, all you need to do is to set A record for your MX domain (normally to the corresponding server IP (second server).


share|improve this answer
For example, I have an ONT optical fiber with two Ports. * Port 1 connects to the router (Int IP: (Ext IP:, the router assigns me an internal IP for the Web Server ( -> * Port 2 connects to the mail server (Ext IP: How difficult here, I need all the webserver send mails ( THROUGH send them mail server ( – blackriderws Aug 9 '11 at 23:19
Ok, If I understand you correctly, you are trying to forward all your OUTGOING mails through your mail server, right ? If this is the case, you just need to check the SMTP forwarding documentation for your local mail server(server 1). For example, if you are using postfix, you can either set transport_maps in your postfix configuration or set relayhost in the configuration. Docs:<br/> [link] <br/> If you are simply using sendmail, then check <br/> [link] – SparX Aug 10 '11 at 0:00
Docs: If you are simply using sendmail, then check – SparX Aug 10 '11 at 0:08
Thank you very much your answer is so usefull. :) – blackriderws Aug 10 '11 at 0:13

Assuming I understand your scenario: You want all traffic from external clients to hit server 1 and be immediately forwarded to server 2 and yet still appear to server 2 to be coming from the clients, not server 1.

First, check to see if IP forwarding is enabled on your Linux box and / or simply enable it using sysctl:

sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

Next you to some iptables magic that reroutes all packets to the new server:

iptables -t nat -D PREROUTING -p tcp –dport destination-port-goes-here -j DNAT –to-destination

With the above done, you should have all traffic being forwarded to the new server, but the packets should appear to be coming from the clients and not the server that is doing the forwarding. Of course, verify all of this for yourself before implementing.

share|improve this answer

ferm is a really handy tool for managing these rules if you end up getting very many of them

share|improve this answer

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.