2

I get a bunch of mail on about 20 different servers that I'd like to get to one. The boxes are running Linux and right now my solution is to create a TCP relay.

I want anytime traffic coming in on port 25 for it to be relayed over to a box somewhere else not on the same LAN. I have a Perl script which does roughly this but it's inefficent and can crash. I'd rather find a way using iptables/ipchains if there is such a way. I think there is but I don't have the technological skill to understand it.

9

Maybe there is no need to have 20 servers for mail? You can just set the MTA (Mail Transfer Agent) on the central server to accept mail for the domain(s) you're interested in, and set the DNS for each domain so that MX record points to the central server.

If that's not possible, make your servers act as mail gateways and relay the mail to the central server. That would take care of the efficiency & reliability problems. How you do that depends on the MTA you've chosen. Of course, you still have to configure the central server to accept mail for all of the domains.

And if you absolutely want to try out your luck with iptables (not recomended) then you could do something like:

iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 25 -j DNAT --to 192.168.1.50:25
iptables -A INPUT -p tcp -m state --state NEW --dport 25 -i eth1 -j ACCEPT
| improve this answer | |
7

I recommend approaching this problem at a higher layer in the network stack. Rather than forwarding ports, you should simply run a simple SMTP server on each host that funnels everything to your central server.

Depending on your needs, you could use:

  • postfix
  • ssmpt
  • qmail
  • ...
| improve this answer | |
  • +1: you should have a central mail server and use a nullclient configuration on your non-mailhosts to forward their mail to that server. – MikeyB Jun 24 '09 at 1:14
3

Perhaps you can solve the problem in DNS.

Simply point the MX records for those 20 servers to the one server you want to use.

| improve this answer | |
  • I vote for this, combined with XYZ's suggestion of having one machine configured for all domains. – Matt Simmons Jun 24 '09 at 11:58
1

Add the following line to each machines' /etc/postfix/main.cf file, and issue a postfix reload

relayhost = smtprelay.yourdomain.com

You'll need to ensure that on smtprelay.yourdomain.com, mynetworks includes the netmask of the machines you want to relay via that machine.

| improve this answer | |
0

If your machines are already running a SMTP server why not set up an alias on each to point to your central mail server?

| improve this answer | |
0

Also, somewhat on-topic.. consider forwarding mail from specific user accounts to a centralised mailbox, using /etc/aliases, like this:

# Person who should get root's mail
root:           hostmaster@company.com

This is a good way to follow things like sudo/sshd/yum notifications from different servers in one mailbox.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy