Port 25 (SMTP)
Key facts
- Port
- 25
- Protocols
- TCP
- Range
- System port (Well-Known), 0-1023
- IANA service name
- smtp
IANA assigns ports in this range to well-known services, under RFC 6335.
About port 25
Port 25 is the port of SMTP (Simple Mail Transfer Protocol), which mail servers use to pass messages to each other, over TCP. When you send an email to an address on another domain, the sender's mail server connects to port 25 of the mail server listed in the receiving domain's MX record.
The protocol is defined in RFC 5321, and IANA registers port 25 for the smtp service.
What port 25 is used for
Port 25 is mainly used to relay mail between servers, not to send from a user's email client:
- Receiving mail: a mail server that receives messages for a domain listens on port 25, and every mail server that delivers to it connects on this port.
- Sending mail to other servers: the mail server opens an outgoing connection to port 25 of the destination server.
- Sending from an email client or a website: email clients, phones, and websites send through the mail server with a username and password, on port 587 or port 465, not on port 25.
Encryption on port 25 uses the STARTTLS command: the connection starts unencrypted, and the two servers switch to an encrypted connection when both support it.
Port 25 in the firewall
On a mail server that receives messages, port 25 must be open to incoming connections from any address, because mail servers all over the world deliver to it. So there's no point in limiting it by IP address.
- UFW:
ufw allow 25/tcp - firewalld:
firewall-cmd --permanent --add-service=smtp
A web server that doesn't receive mail doesn't need port 25 open to incoming traffic. Some internet and cloud providers block outgoing traffic on port 25, which is why websites and email clients send through an authenticated mail server on port 587 or 465.
Risks and security
The most important point on a mail server is that it must not act as an Open Relay, meaning it must not pass on messages from any sender to any destination. A properly configured server accepts on port 25 only messages for its own domains, and relays only messages from authenticated users.
- Make sure the mail server doesn't relay messages without authentication.
- Set up SPF, DKIM, and DMARC records for the domain, so other servers can verify that your messages are genuine.
- Turn on spam filtering and virus scanning for incoming messages.
- Set up an SSL certificate for the mail server, so STARTTLS works and messages travel between servers over an encrypted connection.
Commands to check and configure
-
ss -tlnp | grep ':25 'Checks whether a mail server is listening on port 25 on the server.
-
dig MX example.com +shortShows the mail servers that receive messages for the domain.
-
nc -zv mail.example.com 25Checks whether port 25 on the mail server is open and reachable from your computer.
-
openssl s_client -connect mail.example.com:25 -starttls smtpChecks that the mail server supports STARTTLS, and shows its certificate details.
-
telnet mail.example.com 25Opens a manual connection to the mail server and shows its greeting line (220).
-
ufw allow 25/tcpOpens port 25 to incoming traffic (UFW).
-
firewall-cmd --permanent --add-service=smtpOpens port 25 to incoming traffic in firewalld. Then run firewall-cmd --reload.
Port 25 in the IANA registry
| Port | Protocol | Service | IANA registry description |
|---|---|---|---|
| 25 | TCP | smtp | Simple Mail Transfer |
| 25 | UDP | smtp | Simple Mail Transfer |
Data source: IANA Service Name and Transport Protocol Port Number Registry (opens in a new tab)
Port 25 FAQ
Can I send email from an email client through port 25?
We don't recommend it. Port 25 is meant for relaying mail between servers, and some internet providers block it for outgoing traffic. In your email client, set up the outgoing mail server with a username and password, on port 465 with SSL/TLS or on port 587 with STARTTLS.
How do I send email from a website reliably?
The reliable way is to send through a mail server with authentication, on port 587 or 465, and not by connecting directly to port 25 of the destination servers. This way, messages leave from a mail server with valid SPF and DKIM records, and they're more likely to reach the inbox rather than the spam folder. In WordPress, for example, you do this with an SMTP plugin.
What is an Open Relay?
An Open Relay is a mail server that passes on messages from any sender to any destination, without authentication. Spammers look for servers like this, so it's important to make sure your mail server relays only messages from authenticated users. A simple check of the server settings makes sure of that.
What's the difference between port 25 and ports 465 and 587?
Port 25 is used to relay mail between mail servers. Ports 465 and 587 are used by people sending mail, from an email client or a website, and they require a username and password. On port 465 the connection is encrypted from the start, and on port 587 encryption is started with STARTTLS.