Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk10 min

How to Open Port 25 on an Ubuntu Server (Safely and Verify It)

Opening Ubuntu port 25 requires a listening SMTP service, a matching UFW rule, and permission through any provider firewall. This guide shows the commands, secure source restrictions, external tests, and layer-by-layer troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To open SMTP port 25 on Ubuntu, you need three things working at the same time: an SMTP service listening on the server, a host firewall rule permitting TCP/25, and any upstream cloud or network firewall allowing the connection. A UFW rule by itself does not create a mail service.

Check the listener with sudo ss -utlnp | grep ':25', allow the port with sudo ufw allow 25/tcp, verify the effective policy, and test from a different machine with nc -vz server.example.com 25 or telnet mail.example.com 25. The guide below explains each layer, how to restrict access, and how to diagnose a port that still appears closed.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What an open port 25 actually means

Ubuntu security documentation defines an open port as a network port that is bound to a service and actively listening for incoming connections or packets. In practical terms, opening port 25 is not a single firewall command. It is the result of three independent conditions:

  1. A local SMTP daemon is listening. A process such as Postfix must bind to TCP port 25 on an address reachable by the intended clients.
  2. The Ubuntu host firewall permits the traffic. If UFW is active and denies TCP/25, packets can reach the server but will not be accepted.
  3. Upstream controls permit the traffic. A cloud security group, hosting-provider egress or ingress policy, router ACL, or corporate network may block port 25 even when UFW is configured correctly.

These layers explain the common situation in which an administrator adds an allow rule but an outside test still fails: the rule changes only one layer, and a firewall rule cannot make a non-listening port accept connections.

Decide whether you need inbound port 25

Inbound Internet delivery

Port 25 is the traditional server-to-server SMTP channel. A server receiving mail directly from other mail systems needs an SMTP daemon listening on TCP/25 and must be prepared to handle untrusted Internet traffic. That normally means configuring Postfix (or another SMTP server), setting recipient and relay policy, and ensuring DNS and mail-routing choices are correct for your domain. Opening the port before those controls are in place can expose a misconfigured service.

Outbound delivery or relay

Do not expose port 25 merely because an application must send mail. Outbound SMTP and inbound delivery are different traffic directions and policy decisions. An application can submit mail to a local or managed relay without accepting unsolicited inbound connections. If your provider supplies a relay, follow its connection and authentication requirements instead of creating a public listener.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Private senders and relays

If only one known system should connect, use a source-restricted UFW rule rather than permitting every address on the Internet. This is appropriate for a backup mail host, an internal application, or a designated relay. Confirm that the sender’s address is stable; dynamic addresses can make a narrowly scoped rule stop working.

Check the server before changing UFW

Confirm the current firewall state

Run:

sudo ufw status verbose
sudo ufw status numbered

status verbose shows whether UFW is active and displays the default policies. status numbered lists rules with numbers, which is useful when you later need to insert, remove, or audit a rule. If UFW is inactive, the absence of a UFW rule does not prove that the port is reachable; another firewall may still be filtering traffic.

Find a process listening on TCP/25

Run:

sudo ss -utlnp | grep ':25'

The command lists listening TCP and UDP sockets and the owning process. A result containing TCP port 25 identifies the daemon that will answer connections. Pay attention to the local address: a listener bound only to a loopback address such as 127.0.0.1:25 accepts local connections but is not reachable through the server’s external address. A listener on an external IPv4 address, 0.0.0.0:25, or an appropriate IPv6 address can accept traffic on those interfaces, subject to firewall and provider policy.

If the command returns no line for port 25, stop at this point and configure an SMTP service. Adding a UFW rule while no daemon is listening will still produce connection refusals or timeouts from remote clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install and configure an SMTP service

Use Postfix when the server must receive mail

Ubuntu documents Postfix as an SMTP server. Install it from the Ubuntu package repositories using your normal package-management process, then complete the package configuration for the server’s hostname, mail domain, local destinations, and delivery model. A typical installation command is:

sudo apt update
sudo apt install postfix

During setup, choose the mode that matches your architecture. A server delivering mail directly needs a configuration that accepts mail for domains it is authoritative for; a relay-only host should send through its designated relay and should not act as an open relay. Review the generated configuration before exposing it to untrusted networks.

Verify the daemon and binding

After configuration, restart or reload Postfix using the service-management method appropriate to your Ubuntu release, then run the ss command from the previous section again. The expected result is a Postfix process listening on TCP/25 at the interface intended for incoming connections. If it listens only on loopback, adjust the service’s interface settings deliberately rather than opening the firewall and assuming the bind address will change automatically.

Apply relay and authentication controls first

Postfix must not accept arbitrary messages from arbitrary senders for arbitrary destinations. Configure relay restrictions and authentication-related settings before accepting Internet traffic. Ubuntu’s Postfix guidance notes that the Ubuntu package installs in a chroot by default as a security measure; retain that protection unless you have a documented reason to change it and understand the operational consequences. Test local delivery, rejected recipients, and authenticated relay behavior before publishing the service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Allow TCP port 25 through UFW

Preview the change

You can inspect the rule UFW would generate without applying it:

sudo ufw --dry-run allow 25/tcp

This is useful on production systems where a change should be reviewed before it alters the active policy.

Add an unrestricted rule

To allow TCP port 25 from any source address permitted by other network controls, run:

sudo ufw allow 25/tcp

UFW also accepts the service-name form:

sudo ufw allow smtp

The explicit protocol form is easier to audit because it states that only TCP/25 is being allowed. SMTP is a TCP service; opening UDP/25 is not required for SMTP connections.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enable UFW safely on a remote server

If UFW is not active and you intend to enable it, make sure your SSH rule is present first. Otherwise, enabling the firewall can terminate your administrative access. A safe sequence is to permit SSH according to your management policy, add the required mail rule, and only then run:

sudo ufw enable

Check the result with:

sudo ufw status verbose

Confirm that the output shows UFW active, the expected default policies, and an allow rule for TCP/25. If a provider firewall is also in use, the host-level status is only one part of the final path.

Restrict the source when possible

For a known sender or relay, limit the rule to its address:

sudo ufw allow from 203.0.113.10 to any port 25 proto tcp

The address above is an example documentation address. Replace it with the real, stable source address authorized to connect. A source restriction reduces exposure, but it does not replace SMTP authentication or relay controls inside Postfix.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check provider and network firewalls

Cloud platforms and hosting networks may filter SMTP independently of Ubuntu. Some accounts or regions restrict inbound or outbound port 25 to reduce abuse. A router, perimeter firewall, virtual network ACL, or corporate egress policy can have the same effect. Check the provider’s firewall or security-group configuration for the server’s actual account and region, and verify that it allows inbound TCP/25 from the sources you intend to serve.

Keep the scopes aligned. An unrestricted UFW rule cannot override a provider rule that permits only one address, and a provider rule cannot make a local service reachable when Postfix is bound only to loopback. Document both policies so a later administrator does not remove one layer believing the other still provides protection.

Test port 25 from another machine

Use netcat for a TCP reachability test

From a host outside the Ubuntu server’s network, run:

nc -vz server.example.com 25

Use the server’s public DNS name or address. A successful result means that a TCP handshake completed from that source to port 25. It does not prove that the SMTP service has correct DNS, TLS, authentication, recipient policy, relay restrictions, or mail reputation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Telnet to observe the SMTP banner

Ubuntu’s Postfix documentation uses:

telnet mail.example.com 25

If the connection succeeds, an SMTP server normally presents a greeting banner. The banner confirms that an application answered after the TCP handshake, while a timeout or refusal points to a different layer. Exit the Telnet session without sending test mail unless you understand the SMTP commands and the recipient policy configured on the server.

Test from the right source

A test from the same server can succeed even when Internet clients are blocked, because it may bypass provider filters or use the loopback interface. Perform at least one test from a separate network, and repeat it from each source that should be authorized when you use a source-restricted rule. If IPv4 and IPv6 are both published, test each address family separately; a working IPv4 path does not guarantee an IPv6 path.

Troubleshoot a port that still appears closed

Observed result Likely layer What to check next
ss shows no listener on 25 Service Install or start Postfix, inspect its configuration and logs, and verify again with sudo ss -utlnp | grep ':25'.
Local test works, remote test is refused Binding or service policy Check whether Postfix listens only on loopback or a private address. Confirm that the daemon is configured to accept connections on the intended interface.
Remote test times out, but a listener exists Firewall or upstream network Review sudo ufw status verbose, provider security rules, router ACLs, and any account-level SMTP restrictions.
UFW rule exists but traffic is denied Rule order or source scope Use sudo ufw status numbered to inspect ordering and whether an earlier deny or a source-restricted rule matches the client.
TCP handshake succeeds, but SMTP rejects mail Postfix policy Check recipient domains, relay restrictions, authentication, TLS requirements, and the server’s mail-domain configuration. Port reachability is already established.
One network can connect and another cannot Path-specific filtering Compare source addresses, IPv4 versus IPv6, provider rules, and the exact DNS address each client resolved.

Do not “fix” a timeout by repeatedly adding identical UFW rules. First identify which layer failed. Duplicate rules make audits harder and do not repair a missing listener or an upstream block.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Security considerations before public exposure

Minimize the exposed surface

Ubuntu warns that open ports on untrusted networks create risk when the listening service is vulnerable or misconfigured. Open only ports required by the architecture, keep Ubuntu and Postfix updated through your normal maintenance process, and remove temporary test rules when the work is complete.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prevent open-relay behavior

An Internet-facing SMTP listener must distinguish mail addressed to domains it serves from attempts to relay to arbitrary destinations. Configure relay restrictions and authentication before allowing broad ingress. Test both an authorized message path and an unauthorized relay attempt from a controlled client; the latter should be rejected according to your policy.

Protect administrative access

When changing UFW remotely, preserve a tested SSH rule before enabling or tightening the firewall. Keep a console or out-of-band recovery path available for production systems. Record the source-restricted addresses, provider rules, and the person responsible for each exception.

Separate transport security from port access

A successful connection to TCP/25 does not establish encryption, authentication, or sender reputation. Those are properties of the SMTP configuration and the mail system around it. Treat the firewall rule as network reachability only, then validate the protocol and identity controls independently.

Choose the implementation that fits the mail flow

Approach When it fits Port-25 exposure Administrative trade-off
Local Postfix receiving Internet mail The server is responsible for accepting mail for its domains. Usually public inbound TCP/25, subject to provider approval. You manage updates, relay policy, authentication, logs, DNS, and reputation.
Source-restricted Postfix Only a known relay, application, or private network should connect. TCP/25 allowed only from specified addresses. Lower exposure, but address changes require firewall updates.
Managed relay An external mail service handles delivery and policy. Inbound port 25 on the Ubuntu host may be unnecessary. Less local mail administration; you must follow the relay’s authentication and network requirements.
Authenticated submission on another service port Applications or users send through a controlled submission endpoint. Port 25 need not be open to the public for this use. Clients authenticate to submit; exact port and TLS settings come from the service configuration.
Provider firewall plus UFW Servers protected by both host and cloud or perimeter controls. Both layers must permit the same intended sources. Provides layered policy, but troubleshooting requires checking both rule sets.

Provider restrictions vary by account and region, so confirm the policy for the specific server instead of assuming that a rule documented for another environment applies to yours.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remove the rule when port 25 is no longer needed

Closing an unnecessary port reduces exposure. Remove the unrestricted rule with:

sudo ufw delete allow 25/tcp

If you created a source-restricted rule, delete that exact rule. Use sudo ufw status numbered first if you need to identify the rule’s number, then verify the resulting policy with sudo ufw status verbose. Removing the UFW rule does not stop Postfix; it only changes whether the host firewall permits matching traffic. Stop or reconfigure the service separately if the listener itself should disappear.

End-to-end procedure

Use this sequence when you need a repeatable change window:

  1. Define the mail flow: direct inbound delivery, a private relay, application submission, or a managed relay.
  2. Confirm that exposing inbound TCP/25 is required for that flow and obtain any provider approval.
  3. Install and configure Postfix or the SMTP service, including recipient, relay, and authentication policy.
  4. Run sudo ss -utlnp | grep ':25' and verify that the process listens on the intended address rather than only loopback.
  5. Review UFW with sudo ufw status verbose and sudo ufw status numbered. Preserve SSH access before enabling UFW.
  6. Preview and apply either sudo ufw allow 25/tcp or a source-restricted rule such as sudo ufw allow from 203.0.113.10 to any port 25 proto tcp.
  7. Align cloud, provider, router, and perimeter policies with the same source and protocol scope.
  8. From an external machine, run nc -vz server.example.com 25 or telnet mail.example.com 25, then test SMTP policy separately.
  9. Document the rule and remove it with sudo ufw delete allow 25/tcp when the mail flow no longer needs inbound port 25.

If the external handshake succeeds, the network path to port 25 is open. Any remaining failure belongs to SMTP configuration, authentication, DNS, recipient policy, TLS, or mail-delivery reputation rather than the UFW allow rule itself.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.