Faztek's unnofficial Blog

My first blog is dedicated to Internet hosting software.

quarta-feira, novembro 14, 2007

A Freesco box running an intranet MTA for outbound email

With Exim4 you can use "local_interfaces" configuration to restrict the interfaces it listens port 25 (the SMTP connection port), or even change the listening port.
Restricting the interface to your local intranet is easy:
  • local_interfaces = <; 127.0.0.1.25 ; 10.0.0.20.25
In this case only the local loop interface (aka lo) and one of the networks (in my case the Freesco box has it's local intranet interface, eth1, at 10.0.0.20).
It is possible to combine this Exim (let's call it the intranet-MTA) with another instance of Exim running for inbound email (the most usual usage of Exim in Freesco boxes... let's call it internet-MTA), as follow:
  • local_interfaces = <; 85.2.3.4.25
85.2.3.4 is just an example to illustrate the fact you can only select an IP interface by it's IP address, not an ethernet device (like ppp0, or any other.)
Usually people running Freesco boxes use dynamic IP addresses, so this IP is not fixed at all.

It is possible to tackle this problem as follow.
There is a special argument that is passed to the /rc/rc_user when an IP changes: it's the 'newip' part of this script; I have chosen to restart Exim in this situation, to allow a new configuration (with updated IP) to be taken for the internet-MTA.
Starting Exim in a Freesco box: there is usually an associated starting script (/pkg/rc/rc_exim) that should be able to launch both intranet and internet-MTAs. For the internet-MTA there is a teak: the configuration is generated due to the nature of the dynamic IP.
Refer to the following excerpt:
MY_IP=`ifconfig ppp0 | grep inet.addr: | sed 's/.* addr:\([^ ]*\) .*/\1/'`
MY_A=/usr/exim/conf-autogen
echo "local_interfaces = <; ${MY_IP}.25" > $MY_A
cat /usr/exim/conf-init >> $MY_A
/bin/exim -C /usr/exim/intra.conf -bd -q30m -om
/bin/exim -bd -q30m -om
This will depend on how you have installed Exim. The version I actually use takes the configuration file at: /usr/exim/configure. The first Exim call chooses the fixed configuration (for the intranet-MTA), whilst the second call executes the usual internet-MTA.

The first is used for all my intranet outbound messages, the second for all inbound messages.
The port is always the standard (25, i.e. SMTP).

Naturally the inbound configuration is much more strict: should not allow any relay, contains some spam-blocking, etc. On the other hand, the outbound configuration is totally relaxed, allowing relay to any host (foreign MTAs, usually on the internet.) I assume thereby all intranet insiders behave well, do not send spam, etc.

The motivation for achieving this scheme: if I used a single Exim instance, and since I run greylist, all mails sent to the outside world would be stalled for around 1 hour (until the greylist expires), or eventually have an error on the MUA, something like: "your message could not be sent". It is also possible to costumize the inbound and outbound Exim instances, in a much easier way.

1 Comments:

At 18 janeiro, 2008 18:29, Blogger Henrique said...

Listing listening ports / interfaces on my Freesco box (below):
- the first threelines show three SMTP listening ports.

I actually run two instances of Exim; the first is the internet instance, configured strictly as usual (no relay, etc), and is relaunched whenever IP changes: 85.243.100.25:25.

The second Exim instance (process) deals with intranet requests, with a really relaxed configuration: serves one eth (10.0.0.20:25) and local-loop (127.0.0.1:25).


You also see a CNTP server (gcntpaserver), just serving the local intranet (10.0.0.20:1563).


* net-tools 1.60
=> netstat 1.42 (2001-04-15)
+++clip+++
[Linux] netstat -t -l -n -p
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 85.243.100.25:25 0.0.0.0:* LISTEN 31265/exim
tcp 0 0 10.0.0.20:25 0.0.0.0:* LISTEN 31263/exim
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 31263/exim
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN 11616/telnetd
tcp 0 0 10.0.0.20:1563 0.0.0.0:* LISTEN 2971/gcntpaserver
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 2851/teapop
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2475/sshd
tcp 0 0 0.0.0.0:113 0.0.0.0:* LISTEN 2126/
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3436/httpd
tcp 0 0 0.0.0.0:82 0.0.0.0:* LISTEN 1926/thttpd
+++clip+++

 

Enviar um comentário

<< Home