How to Test Port 25 in CentOS and Ubuntu (All Versions)

by techtrendsdeals
Testing SMTP port 25 in CentOS and Ubuntu using Linux commands

SMTP (Simple Mail Transfer Protocol) uses port 25 for sending emails. Many cloud providers block this port to prevent spam, making it crucial to check if your server can send emails via port 25.

In this guide, we will show you how to test port 25 in CentOS and Ubuntu (all versions), troubleshoot blocked ports, and fix issues caused by cloud providers or firewalls.


Why Test Port 25?

Testing port 25 is essential for:
✔️ Verifying if your server can send emails.
✔️ Troubleshooting SMTP issues when emails fail to send.
✔️ Checking if your cloud provider has blocked port 25.
✔️ Identifying firewall rules that may be blocking SMTP traffic.

If port 25 is blocked, emails won’t be sent from your server, and you may need to use an alternative port like 587 or 465.


How to Test Port 25 in CentOS and Ubuntu

Method 1: Using Telnet

Telnet is a simple way to check if port 25 is open. If it’s not installed, install it first:

For CentOS/RHEL:

sudo yum install telnet -y

For Ubuntu/Debian:

sudo apt install telnet -y

Now, test port 25:

telnet smtp.gmail.com 25

If port 25 is open, you will see a response like this:

Trying 74.125.137.109...
Connected to smtp.gmail.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP

If the connection fails, port 25 is likely blocked.

Method 2: Using Netcat (nc Command)

Netcat (nc) is another tool to check port connectivity:

Install netcat if not already installed:

sudo yum install nc -y  # CentOS
sudo apt install netcat -y # Ubuntu

Run the following command:

nc -zv smtp.gmail.com 25

If port 25 is open, you’ll see:

Connection to smtp.gmail.com 25 port [tcp/smtp] succeeded!

Method 3: Using Nmap

If telnet and netcat are not available, use Nmap:

Install Nmap:

sudo yum install nmap -y  # CentOS
sudo apt install nmap -y # Ubuntu

Run:

nmap -p 25 smtp.gmail.com

If port 25 is open, it will show:

PORT   STATE SERVICE
25/tcp open smtp

If it’s filtered or closed, port 25 is blocked.


How to Fix Blocked Port 25 Issues

If port 25 is blocked, the issue could be with your cloud provider or firewall settings. Here’s how to fix it.

1. If Port 25 is Blocked by Cloud Provider

Some cloud providers block port 25 by default. Check with your provider:

Related: Buy Cloud accounts with Port 25 Enabled for cheap Price

🔹 AWS (Amazon Web Services): AWS blocks port 25 for EC2 instances. You need to request unblocking via AWS Support.

🔹 Google Cloud (GCP): Google Cloud does not allow outbound SMTP on port 25. Use port 587 instead.

🔹 Azure: Microsoft Azure blocks port 25 on new VM instances. You must use port 587 or 465.

🔹 DigitalOcean & Linode: Both block port 25 on new accounts. You can request an unblock by contacting their support.

🔹 Vultr: By default, port 25 is blocked, but you can open a support ticket to request unblocking.

Solution: Use Alternative SMTP Ports

If your cloud provider refuses to unblock port 25, use port 587 (STARTTLS) or port 465 (SSL/TLS). Modify your SMTP configuration to use these ports instead of 25.

Example command to test port 587:

telnet smtp.gmail.com 587

2. If Cloud Provider Allows Port 25 but Firewall Blocks It

If your provider has unblocked port 25 but it’s still not working, check your firewall settings.

Check and Allow Port 25 in FirewallD (CentOS/RHEL 7/8/9)

Run:

sudo firewall-cmd --list-all

If port 25 is missing, add it:

sudo firewall-cmd --add-port=25/tcp --permanent
sudo firewall-cmd --reload

Check and Allow Port 25 in UFW (Ubuntu/Debian)

Run:

sudo ufw status

If port 25 is blocked, allow it:

sudo ufw allow 25/tcp
sudo ufw reload

Check Iptables (If FirewallD or UFW Is Not Used)

Run:

sudo iptables -L -n | grep :25

If port 25 is blocked, allow it:

sudo iptables -A INPUT -p tcp --dport 25 -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 25 -j ACCEPT
sudo service iptables save

After making these changes, restart your mail server:

sudo systemctl restart postfix
sudo systemctl restart exim

Final Thoughts

Testing port 25 in CentOS and Ubuntu helps diagnose SMTP issues. If port 25 is blocked:
✅ Check if your cloud provider has blocked it.
✅ If allowed by the provider, ensure it’s open in your firewall.
✅ Use alternative SMTP ports (587 or 465) if necessary.

By following this guide, you can quickly test and fix port 25 issues for smooth email delivery. If you need further assistance, consult your hosting provider or switch to a different SMTP service.

Related Posts

Leave a Comment