Resources · Port reference · port 25
Port 25 (SMTP): what it is and how to secure it
Port 25 is server-to-server email. Only a real mail server should listen on it publicly. A server that just sends app email should listen on loopback.
Check command
sudo ss -tlnp | grep ':25 '
Copied.
Port 25 is SMTP, how mail servers deliver email to each other. Only a server that receives email for a domain needs to accept connections on 25 from the internet. If your server only sends app email (password resets, receipts), its mail software should listen on 127.0.0.1 only, or you should send through an email provider on port 587 and not run a mail server at all.
What port 25 is for
When someone emails [email protected], their mail server looks up your MX record and connects to that host on port 25. Postfix and Exim are the usual listeners on Linux. Many Ubuntu and Debian servers get Postfix installed as a dependency, and an installer prompt choosing "Internet Site" makes it listen publicly.
Why an open 25 is risky
- Open relay. A misconfigured mail server that forwards mail for anyone becomes a spam cannon. Your IP lands on blocklists within hours, and your real email stops being delivered.
- Attack surface. Mail servers parse untrusted input from the whole internet. Exim in particular has had serious remote bugs, which is why running it unpatched and public is a risk.
- Brute force. If SMTP authentication is offered on 25, bots will try passwords against it.
Check yours
sudo ss -tlnp | grep ':25 '
postconf inet_interfaces mynetworks 2>/dev/null
0.0.0.0:25 with inet_interfaces = all means Postfix accepts mail from the internet.
Fix it: a server that only sends
Make Postfix listen on loopback only:
sudo postconf -e 'inet_interfaces = loopback-only'
sudo systemctl restart postfix
Or, if nothing on the server uses local mail, remove it:
sudo apt remove postfix
Better still for apps: send through a transactional email provider (Resend, Postmark, Amazon SES, Mailgun and others) over port 587 with authentication. Your mail gets SPF and DKIM handled properly and your server runs one less daemon.
Fix it: a real mail server
If this host receives mail, 25 must stay open. Then:
- make sure it is not an open relay: in Postfix,
mynetworksshould list only127.0.0.0/8and[::1]/128, andsmtpd_relay_restrictionsshould end withreject_unauth_destination; - keep the mail software patched;
- publish SPF, DKIM and DMARC records;
- offer authenticated submission on 587, not 25.
Common mistakes
- Picking "Internet Site" in the Postfix installer on a web server that only needs to send.
- Expecting outbound 25 to work on a new VPS. Many cloud providers block outgoing port 25 by default to stop spam. Use 587 to a provider instead.
FAQ
Should I close port 25? Yes, unless the server receives email for a domain.
How do I get warned? PortGate's Server Guard alerts when a mail port starts listening on a public address after your baseline.