I need to open the 25 TCP port on my Raspberry Pi 3, I watched videos on the internet (iptables) nothing works, if you have a solution, using iptables or another method, that would be great.

If you want to know, I'm building an SMTP mail server and I have errors like "connection timed out" (with postfix) when I try to send a mail, (that's why I think port 25 is the problem, because it's closed)

  • Have you enabled any kind of firewalls? Raspbian doesn't have an active firewall by default, so anything that's getting blocked is likely due to something you did.
    – Jacobm001
    Jul 3, 2017 at 14:41
  • When you say try to send a mail do you mean from the RPi or another computer?
    – Jacobm001
    Jul 3, 2017 at 14:41
  • both questions = yup, the problem was in the config, and hostname resolved now
    – Mazeo
    Jul 3, 2017 at 21:00
  • I send from RPI
    – Mazeo
    Jul 22, 2017 at 3:34
  • Port 25 is a special issue. It's commonly used as an open relay for mail, and most of the world's spam can be traced back to it, which is why it is very common for ISPs to block it (meaning, it blocks you from being a spammer, not from receiving it). As far as I am aware it is probably never used by legit email providers now, everything except junk uses encryption.
    – goldilocks
    Apr 14, 2020 at 12:27

2 Answers 2


You likely don't have issues with iptables, unless you installed and configured it as it is not running on a default Raspbian install. Also the default install will normally open and listen on the required ports. However, if you intend on running a mail server you should install and configure a firewall first, as your server will be a prime target for spammers etc. Properly securing a mail server involves considerably more than a firewall though.

As for port 25 It may be blocked by your ISP. I would suggest you implement SSL for your ingoing and outgoing mail which means that you will no longer be using port 25. The default configuration file should have automatically opened the port and be listening.

However, to answer your question you can see if the port is open and what process is listening with the following command:

sudo netstat -lptu

Additionally you can test your basic configuration using telnet as described in this post.

Depending on why you want an email server you may be better off just setting it up to forward all nonlocal mail through your Gmail account. I have not used it recently but this script makes that exceptionally easy.

  • It seem to work ! thanks, actually the problem was both with SSL, and also my fault for badly configuring hostname and domainname. You helped a lot, thanks.
    – Mazeo
    Jun 29, 2017 at 7:38

For me:

sudo ufw allow 9999

works, where 9999 is the port number i want to open.


In case ufw is not installed:

sudo apt-get install ufw

In case ufw is not running (check with sudo ufw status):

sudo ufw enable 

Question already answered?

i asked on meta: Should i place a second answer if question title vs answer differ?.

Not the answer you're looking for? Browse other questions tagged or ask your own question.