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

I have setup Postfix but am having trouble with the setup.

Whenever I used to send emails to the server, it reject my mails saying 'Relaying Denied', so I changed the following in

mynetworks =
mynetworks_style = subnet

I can now send email and it works, but MX tests say that it is an open relay (obviously unintended).

How can I resolve this? I obviously want anybody to be able to email my domain, but I'm unsure of the configuration.

I know I can change the mynetworks, but then doesn't this restrict who CAN email to the server?

share|improve this question
Are you trying to relay mail through this server, or to deliver mail to this server? – nickgrim Aug 29 '12 at 13:22
Makes no difference with respect to this issue, since an open relay is an open relay. Email is not a trivial undertaking. – adaptr Aug 29 '12 at 13:54

mynetworks must only contain trusted users that can use the server to relay mails to other domains - otherwise, as you've found, it's an open relay. You might want to set it to, 10/8 or if using RFC 1918 addresses on your internal network.

The settings that control whether people can send mail to your server include mydestination and virtual_mailbox_domains - read the docs here or here.

share|improve this answer
mydestination, relay_domains, and virtual_[alias|mailbox]_maps. NOT virtual_[alias|mailbox]_DOMAINS. – adaptr Aug 29 '12 at 13:49

The problem that opens you up is the

mynetworks =

Cause somewhere below you probably have it listed in

smtpd_recipient_restrictions = ... permit_mynetworks ...

If you need to be able to send email from any ip then you just look at enabled a user/password to send email which the common one is sasl

share|improve this answer

As documented at :

mynetworks (default: see "postconf -d" output)
The list of "trusted" remote SMTP clients that have more privileges than "strangers".

In particular, "trusted" SMTP clients are allowed to relay mail through Postfix.
See the smtpd_recipient_restrictions parameter description in the postconf(5) manual.

share|improve this answer

use authentification only for yours ip:

smtpd_recipient_restrictions =

use file to store your ip

mynetworks = hash:/etc/postfix/network_table 

Use script to update your ip if change (run in cron)

## sh /sx_sys/

curent_ip=$(dig | awk '/^;; ANSWER SECTION:$/ { getline ; print $5 }')
#echo $curent_ip

saved_ip=$(</etc/postfix/network_table )
#echo $saved_ip
if [ "$curent_ip OK" != "$saved_ip" && -n "$curent_ip"]; then
echo "$curent_ip OK" > "/etc/postfix/network_table"
postmap /etc/postfix/network_table
echo "$(date) smtp allow for $curent_ip" >> $LOGFILE 2>&1
mail -s "smtp allow for $curent_ip $(date)" < /dev/null
exit 0
share|improve this answer

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.