Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

3 Answers

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 mail.yourdomain.com) 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: 192.168.0.1) (Ext IP: 190.6.206.171), the router assigns me an internal IP for the Web Server (192.168.0.11 -> 190.6.206.171). * Port 2 connects to the mail server (Ext IP: 190.6.206.173). How difficult here, I need all the webserver send mails (192.168.0.11) THROUGH send them mail server (190.6.206.173) –  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]postfix.org/SMTPD_ACCESS_README.html <br/> If you are simply using sendmail, then check <br/> [link]cri.ch/linux/docs/sk0009.html –  SparX Aug 10 '11 at 0:00
    
Docs: postfix.org/SMTPD_ACCESS_README.html If you are simply using sendmail, then check cri.ch/linux/docs/sk0009.html –  SparX Aug 10 '11 at 0:08
    
Thank you very much your answer is so usefull. :) –  blackriderws Aug 10 '11 at 0:13
add comment

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 your.IP.goes.here

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
add comment

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

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.