Exim provides a number of facilities for controlling incoming mail from remote hosts, in addition to the verification options described in the previous chapter. These controls can be used to stop unwanted messages getting into your machine. After a message has been accepted, the filtering mechanism described in chapter "System-wide message filtering" can be used to check it before going ahead with delivery.
An MTA is said to relay a message if it receives it from some host and delivers it directly to another host as a result of a remote address contained within it. Expanding a local address via an alias or forward file and then passing the message on to a remote host does not count as relaying. There are special options for controlling which remote hosts may use the local host as a relay.
The options described in this chapter control three stages of checking that are applied to an incoming SMTP message:
These checks are all in addition to any verification that may be enabled. The following sections give details of the various checking options. The `-bh' command line option can be used to run fake SMTP sessions for the purpose of testing them.
The Realtime Blocking List (RBL) is a blacklist of hosts that is maintained in
the DNS. See `http://maps.vix.com/rbl/' for the background to this.
Since the RBL was created, a number of other similar lists (DUL, ORCA, IMRSS)
have sprung up. These all operate in the same way. If the `rbl_domains' option
is set, Exim looks up inverted incoming IP addresses in each of the given
domains, provided the remote host matches `rbl_hosts' (whose default is to
match all hosts). For example, if the setting is
and an SMTP call is received from the host whose IP address is 131.111.8.1,
then DNS lookups for address records for
are done. Each domain in `rbl_domains' can be followed by `/warn' or `/reject'
to specify what is to be done when a match is found, for example:
The action for domains without either of these is controlled by
`rbl_reject_recipients', which implies `/reject' when set.
Warning consists of writing a message to the main and reject logs, and, if
`rbl_warn_header' is true (the default), adding an `X-RBL-Warning:' header to
the message. This can be detected later by system or user filter files. If a
host appears in several RBL lists, more than one such header may be added to a
message.
Rejection is done by refusing all recipients, that is, by giving permanent
error returns to all RCPT commands, except for any recipients that are
listed in
`recipients_reject_except'. It is fairly common to set
to allow your host to accept mail to the postmaster from blacklisted hosts.
If a TXT record associated with the host is found in the RBL domain, its
contents are returned as part of the 550 rejection message, unless
`prohibition_message' is set (see section "Customizing prohibition messages"), in which case a
locally-specified message (possibly including the TXT data) is used. If a
lookup times out or otherwise fails to give a decisive answer, the mail is not
blocked.
rbl_domains = rbl.maps.vix.com:dul.maps.vix.com
1.8.111.131.rbl.maps.vix.com
and
1.8.111.131.dul.maps.vix.com
rbl_domains = rbl.maps.vix.com/warn : dul.maps.vix.com/reject
recipients_reject_except = postmaster@your.domain
Exim rejects incoming SMTP calls from any host that matches `host_reject'.
For example:
rejects mail from any host outside the `zz' domain, and all hosts in the
`yy.zz' domain, except for `xx.yy.zz'. The use of wildcarded names implies a
reverse DNS lookup of the incoming IP address. This can be avoided by using IP
addresses. See section "Host lists" in chapter "The Exim configuration file" for details.
host_reject = ! xxx.yy.zz : *.yy.zz : ! *.zz
Calls are rejected as a result of these options by sending a 5xx error code as soon as the connection is received. Since this does not relate to any particular message, the remote host is likely to keep on trying to send mail (possibly to an alternative MX host) until it times out. This may be what is wanted in some circumstances (for example, you want temporarily to hold back all incoming mail from some host), but when dealing with incoming spam, for example, one normally wants messages to be rejected once and for all, and in thist case, `host_reject_recipients' should be used instead of `host_reject'.
A call from a host which matches `host_reject_recipients' is not rejected at the start; instead, every RCPT command is subsequently rejected, which should cause the remote MTA to cease trying to deliver the message. This style of blocking also has the advantage of catering for exceptions for certain recipients, via the `recipients_reject_except' option. This is commonly set to the local postmaster address.
Incoming messages can be rejected on the basis of the sender address, as given in the MAIL command. A list of senders to reject is set by the `sender_reject' configuration option; see its description in chapter "Main configuration" for details.
Some MTAs continue to try to deliver a message even after receiving a 5xx error code for MAIL. The alternative configuration option `sender_reject_recipients' is provided for use in such cases. It accepts the MAIL command but rejects all subsequent RCPT commands.
There are two aspects of control over relaying via the local host, which might be termed `incoming' and `outgoing'. A host which is acting as a gateway or an MX backup is concerned with incoming relaying from arbitrary hosts to a specific set of domains. A host which is acting as a smart host for a number of clients is concerned with outgoing relaying from those clients to the Internet at large. Often the same host is fulfilling both functions, as illustrated in the diagram below, but in principle these two kinds of relaying are entirely independent, and are therefore controlled by two separate options. What is not wanted is the transmission of mail from arbitrary remote hosts through your system to arbitrary domains.
-------------- ----------- | Arbitrary | |Arbitrary| |remote hosts| | domains | -------------- ----------- I v ^ O n v ^ u c ---v----------------^--- t o | v Local ^ | g m | v host ^ | o i ---v----------------^--- i n v ^ n g v ^ g Specific Specific domains hosts
Incoming relaying is controlled by restricting the domains to which an arbitrary host may send; outgoing relaying is controlled by restricting the hosts which may send to an arbitrary domain. If an arbitrary host can send via the local host to an arbitrary domain, the host is open to abuse.
The relaying check happens whenever a message's recipient is received, that is, immediately after a RCPT command. The first check is whether the address would cause relaying at all: if its domain matches something in `local_domains' then it is destined to be handled on the local host as a local address, and relaying is not involved, unless the `percent hack' is in use. In this case, the local part is converted into a new address and that is then checked.
When the relevant domain is not in `local_domains', there is first a check for legitimate incoming relaying, by seeing if it matches `relay_domains', or, when `relay_domains_include_local_mx' is set, if it is a domain with an MX record pointing to the local host. If it does match, this is an acceptable incoming relay, and it is permitted to proceed.
For example, if the FooBar company has a firewall machine through which all mail from external hosts must pass, and this machine's configuration contains
local_domains = foobar.com relay_domains = *.foobar.com
then mail from external hosts is rejected, unless it is for a domain ending in `foobar.com'.
If a recipient address is neither for a local domain nor an incoming relay, it must be an outgoing relay, and it is accepted only if the sending host is permitted to relay to arbitrary domains, and if the sender address is acceptable. The set of hosts is specified by `host_accept_relay'. For example, if the FooBar company's IP network is 192.153.213.0, and all hosts on that network send their outgoing mail via the firewall machine, then its configuration should contain
host_accept_relay = 192.153.213.0/24
in order to allow only the internal hosts to use it as a relay to arbitrary domains. Exim does not make an exception for the loopback IP address, so if you want to permit relaying from processes on the local host using this method, you need to set
host_accept_relay = 127.0.0.1
In addition to the test on the host, if `sender_address_relay' is set, the sender's address from the MAIL command must match one of its patterns to allow outgoing relaying to an arbitrary domain. Also, if there are any rewriting rules with the `X' flag set, such an address is rewritten using those rules, and the result (if different) must verify successfully. See section "The additional relay checking flag" in chapter "Address rewriting" for an example of how this can be used.
Normally, therefore, both the host and the sender must be acceptable before an outgoing relay is allowed to proceed. However, if `relay_match_host_or_sender' is set, an address is accepted for outgoing relaying if either the host or the sender is acceptable. Of course, sender addresses can easily be forged, but the sender check does mean you can prevent some kinds of unwanted mail from going through your host.
Both `relay_domains' and `host_accept_relay' are unset by default, which means that no relaying of any kind is enabled. This does not prevent a local user from setting up forwarding to some external system, but it does prevent the `percent hack' from working even when `percent_hack_domains' is set.
If you have a list of domains that any host can relay to, but there are no hosts that are permitted to relay to arbitrary domains (for example, if your host is an MX backup for some domains), then set `relay_domains'.
If the recipient address is an RFC 821 source routed address, that is, an address of the form `<@hop1,@hop2:user@domain>', it is the final domain which is tested. By default, however, Exim will send the message to the `hop1' domain, unless it is a local domain. The `collapse_source_routes' option can be used to prevent this.
As all the relay checking is done at RCPT time on incoming messages, the directors and routers are not involved. Depending on the configuration of these drivers, an address that appears to be remote to the relay checking code (that is, its domain does not match `local_domains') may nevertheless end up being delivered locally, and similarly an apparently local address may end up being delivered to some other host.
None of the relay checking applies when mail is passed to Exim locally using the `-bm', `-bs' or `-bS' options, but it does apply when `-bs' is used from `inetd'.
Exim does not attempt to fully qualify domains at RCPT time. If an incoming message contains a domain which is not fully qualified, it is treated as a non-local, non-relay domain (unless partial domains are included in `local_domains' or `relay_domains', but this is not recommended). The use of domains that are not fully qualified is non-standard, but it is a commonly encountered usage when an MTA is being used as a smart host by some remote UA. In this situation, it would be usual to permit the UA host to relay to any domain, so in practice there is not normally a problem.
The diagrams below shows how the various policy checks are applied to an
incoming message from a remote host. The normal flow of control is vertically
down the left-hand set of boxes.
----------------- yes
| host reject? |----------> reject
-----------------
|
----------------- yes -----------------
| host reject |---------->| set HRR flag |
| recipients? | | |
----------------- -----------------
| |
|<---------------------------
|
----------------- found ----------------- yes ----------------
| check RBL |---------->| RBL reject? |----->| set HRR flag |
----------------- ----------------- ----------------
| | |
| ----------------- |
|<------------------| add header | |
| ----------------- |
HELO---- | |
| |<-------------------------------------------------
V |
----------------- fail
| verify HELO |-----> reject
-----------------
|
MAIL---- |
| |
V |
yes -----------------
-----| HRR flag set? |
| -----------------
| |
| ----------------- yes
| |sender reject? |-----> reject
| -----------------
| |
| ----------------- yes ----------------
| | sender reject |---------->| set SRR flag |
| | recipients? | | |
| ----------------- ----------------
| | |
------------>|<--------------------------
|
-----------------
| verify sender |
-----------------
|
RCPT---- |
| |
V |
----------------- yes ----------------- no
|HRR or SRR set?|---------->| recipients |-----> reject
| | |reject except? |
----------------- -----------------
| |
|<---------------------------
|
yes -----------------
-----| local or |
| | relay domain? |
| -----------------
| |
| ----------------- no ----------------
| | host accept |---------->| set HFR flag |
| | relay? | | |
| ----------------- ----------------
| | |
| |<--------------------------
| |
| ----------------- no -----------------
| |sender address |---------->| set SFR flag |
| | relay? | | |
| ----------------- -----------------
| | |
| |<---------------------------
| |
| ----------------- yes ----------------- no
| |relay need host|---------->| HFR and SFR |----------------
| | or sender? | | both set? | |
| ----------------- ----------------- |
| | | |
| ----------------- yes | |
| | SFR set? |------> reject | |
| ----------------- | |
| | | |
| ----------------- yes ----------------- no |
| | HFR set? |---------->| relay domains |-----> reject |
| | | |include lcl MX?| |
| ----------------- ----------------- |
| | | |
| | ----------------- no |
| | | exists MX to |-----> reject |
------------>| | local host? | |
| ----------------- |
| | |
|<---------------------------------------------------
|
-----------------
| verify |
| recipient |
-----------------
If verification of a sender fails, rejection may be immediate, or it may follow later after the RCPT command or after the data has been received (see section "Sender verification" in chapter "Verification of incoming mail"). If recipient verification fails, rejection is immediate.
It is possible to add a site-specific message to the error response that is sent when an incoming SMTP command fails for policy reasons, for example if the sending host is in a host reject list. This is done by setting the option `prohibition_message', which causes one or more additional response lines with the same error code and a multiline marker to be output before the standard response line. For example, setting
prohibition_message = "contact postmaster@my.site for details"
causes the response to a RCPT command for a blocked recipient to be
550-contact postmaster@my.site for details 550 rejected: administrative prohibition
The string is expanded, and so it can do file lookups if necessary. If it ends
up as an empty string, no additional response is transmitted. To make it
possible to distinguish between the several different types of administrative
rejection, the variable `$prohibition_reason' is set to a characteristic text
string in each case. The possibilities are as follows:
In addition, if `relay_match_host_or_sender' is set, there is
host_accept_relay the host is not in an `accept_relay' list
host_reject the host is in a reject list
host_reject_recipients the host is in a `reject_recipients' list
rbl_reject the host is rejected by an RBL domain
sender_relay the sender is not in a sender relay list
sender_reject the sender is in a reject list
sender_reject_recipients the sender is in a `reject_recipients' list
sender_verify sender verification failed
sender+host_accept_relay the sender is not in a sender relay list
and the host is not in an accept relay list
For example, if the configuration contains
prohibition_message = "${lookup{$prohibition_reason}lsearch\ {/etc/exim/reject.messages}{$value}}"
and the file `/etc/exim/reject.messages' contains (inter alia)
host_accept_relay: host not in relay list
then a response to a relay attempt might be
550-host not in relay list 550 relaying to <santa@northpole.com> prohibited by administrator
Because some administrators may want to put in quite long messages, and it isn't possible to get newlines into the text returned from an lsearch lookup, Exim treats the vertical bar character as a line separator in this text. If you want the looked up text to be re-expanded, you can use the `expand' operator. For example, the setting
prohibition_message = "${lookup{$prohibition_reason}lsearch\ {/etc/exim/reject.messages}{${expand:$value}}}"
when used with a file entry of the form
host_accept_relay: Host $sender_fullhost is not permitted to relay |through $primary_hostname.
might produce
550-Host that.host.name [111.222.3.4] is not permitted to relay 550-through this.host.name. 550 relaying to <penguins@southpole.com> prohibited by administrator
When the prohibition is due to an entry in a Realtime Blocking List and a message is available from a DNS TXT record, that text is available in the `$rbl_text' variable. If `prohibition_message' is not set, then the TXT data is always included in the rejection message.
Go to the first, previous, next, last section, table of contents.