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

When I set up an email server using postfix on ubuntu server, how do I make sure that it won't be an open relay??

share|improve this question
up vote 6 down vote accepted

Being an open relay means that you are accepting mail from unauthenticated users for domains that are not the domains you manage.

Postfix has some very simple config options to help: mynetworks and *mynetworks_style* between them dictate from which network addresses messages to any destination will be accepted. mydestination is used to specify which domains are domains that you manage (ie that you should accept messages for because they're yours).

So the very simplest setup looks like:

mydomain =
mydestination = $myhostname, $mydomain
mynetworks =
smtpd_recipient_restrictions = 

This will accept mail only:

  1. for and for the hostname of the host itself, from any machine that can reach your mail server
  2. from any client on the mail server (, for any host, anywhere.

and will reject anything else.

That is the most basic setup I can come up with. You need to read the entries for mydomain, mydestination, mynetworks{_style} in postconf(5).

If you need to be able to accept mail from clients by any other criterion than network, such as say username and password or kerberos ticket, you need to read about SMTP_AUTH.

share|improve this answer

I believe you'll need to set the mynetworks_style, mynetworks, and relay_domains settings in the Postfix configuration file. Basically the first two control which servers Postfix will accept mail from, and the last one controls which servers it will forward mail to. The exact settings depend on how you want your mail server configured (i.e. who is authorized to send emails through the server), but in general relay_domains should be set to only the hostnames of the mail server itself (same as mydestinations) and mynetworks_style can be set to host which means only accept emails from the local host itself.

There are some tests listed at that you can use to check whether your server is running an open relay. (Some of the links may be dead but I'm pretty sure at least one still works... don't remember which though)

Here's an excerpt from my server's Postfix config:

luser_relay =
mydestination = $myhostname, $mydomain, localhost, localhost.$mydomain
mynetworks = [server's IP address]/32
mynetworks_style = host
myorigin = $mydomain
relay_domains = $mydestination
smtpd_helo_restrictions = permit_mynetworks,
smtpd_recipient_restrictions = permit_sasl_authenticated,
        check_policy_service unix:private/postgrey,
        check_policy_service unix:private/policyd-spf,
share|improve this answer

Give this website this website a try. It will allow you to check that you've configured your mail server properly

Updated as the first website no longer works

share|improve this answer
Update on 2015: The relay tester is no longer available. Mail software is rarely an open relay any more unless it is badly misconfigured. – masegaloeh Jan 6 '15 at 11:12
@masegaloeh Thanks for pointing that out. I've put a link to a new website there instead. – Matthew Steeples Jan 6 '15 at 22:58

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.