Need help choosing hosting?Live chatSupport
Client Area
SMTP Mailing VPS

How to Prevent an Open Relay on a Linux SMTP Server

Learn how to prevent an open SMTP relay on Linux. Secure Postfix and Exim, configure relay restrictions, test access, and protect your mail server from abuse.

By James RadyNovember 10, 20263 min readUpdated November 10, 2026

An open relay on a Linux SMTP server allows unauthorized users to forward email through your machine to unrelated recipients. Attackers can exploit this mistake to send spam, overload queues, and damage your IP reputation.

Fortunately, proper relay restrictions and a simple external test can help prevent it.

What Is an SMTP Open Relay?

A legitimate mail server accepts messages for its own domains and forwards outbound mail for trusted clients or authenticated users.

An open relay accepts messages from an unauthenticated outsider addressed to another external domain. This differs from accepting legitimate incoming mail for your hosted domains.

Open Port 25 does not automatically mean your server is an open relay.

1. Check Postfix Relay Restrictions

For a Postfix server, inspect the active configuration:

sudo postconf smtpd_relay_restrictions mynetworks relay_domains

A typical modern relay policy is:

smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

The first rule trusts specified network addresses; the second permits authenticated clients; the final rule rejects unauthorized external destinations.

Review mynetworks carefully. Never trust every internet address or a broad subnet you do not control.

Refer to the official Postfix SMTP Access Control Guide before modifying production settings.

2. Secure Authenticated Submission

Configure SMTP authentication for trusted applications on Port 587 with required STARTTLS or Port 465 with implicit TLS.

Use strong, unique credentials. Do not enable unrestricted relaying on Port 25 simply to make an application work.

After modifying Postfix, run:

sudo postfix check

Then reload safely with sudo postfix reload.

3. Verify Exim Relay Controls

On Exim, inspect the recipient ACL configured by acl_smtp_rcpt.

Ensure it accepts relaying only from explicitly trusted hosts or authenticated clients, while denying unrelated external recipients.

If you use cPanel/WHM, make changes through supported controls rather than overwriting generated Exim configuration.

4. Test From an Untrusted Network

From a different internet connection, test without SMTP credentials:

swaks --server mail.example.com --port 25 --from sender@outside.example --to recipient@another.example --quit-after RCPT

Use your actual server hostname, and check that an external-to-external delivery request receives a relay-denied response. This test stops before sending message content.

Also confirm legitimate local delivery and authenticated submission still work.

5. Monitor Abuse and Mail Queues

Review SMTP logs for unexpected relay attempts, authentication failures, and sudden sending spikes.

Keep Postfix or Exim updated, restrict administrative access, and monitor queues. Fail2ban and rate limits add protection, but cannot repair permissive relay rules.

VeltrixHost SMTP VPS Hosting provides root access, Port 25 availability, and PTR/rDNS controls for self-managed infrastructure.

Final Recommendation

To prevent an open relay on a Linux SMTP server, restrict trusted networks, require authenticated submission, and test from outside your VPS.

Recheck the policy after mail-software upgrades and major configuration changes.

FAQs

Is having Port 25 open unsafe?

Not by itself. Incorrect relay permissions create the open-relay risk.

Can SPF or DKIM stop an open relay?

No. They authenticate sender identities or messages; relay access requires separate controls.

Should I test relaying from localhost?

Test locally and externally. Localhost may be trusted, so it cannot prove outsiders are blocked.

Written by

James Rady

VeltrixHost editorial team publishing practical hosting, VPS, dedicated server, email infrastructure and performance guidance.