Hope you are doing well.
As we know Email is the basic part/need of our life. We are surrounded by and depended on it. Our regular and important task also depends on it. We send and receive mail every day.
If we talk about working on emails then we can say that it works on mainly 2 protocols. SMTP and POP/IMAP.
SMTP which is called as Simple Mail Transfer Protocol is used for sending emails and it works on standard port 25, port 465 (Non-secure) and port 587 (secure).
POP/IMAP (Post Office Protocol/ Internet Access Message Protocol) used for receiving emails and it works on standard port 110 and port 143 respectively (Non-secure) & port 995 and port 993 respectively (secure).
We might have noticed that our ISP (Internet Service Provider) blocks our default/standard port for security purpose. Generally, they block non-secure SMTP port i.e.25.
If you come across such situation, do not panic. I will discuss here how you can use another port for your SMTP service. I will discuss Postfix in this post as I have seen it is mostly used for emails. So let’s start.
First, execute the below command and check which port is running for SMTP service in your server:
The above command will show on which port SMTP is running.
As we see that port 25 is used for SMTP service. Let’s check whether the server: 184.108.40.206 is listening to this port or not (from outside).
Execute the below command to check whether port 25 is listening or not.
telnet 220.127.116.11 25
As we see that server: 18.104.22.168 is listening to port 25.
As many ISP blocks this port for security reason, we will run the SMTP service on a different port so that we can send our emails without any issue. Let’s say we want to run the SMTP service on the port 2525. The steps are very simple. Please follow the below steps:
- Go to the directory /etc/postfix and you will see a file name called master.cf.
- First of all, take a copy of this file (for the safety purpose). Refer the below snapshot for your reference.
- Now open the file master.cf and find the line labelled as: ‘smtp inet n …..’
- Just below the line, insert the new line containing the following:
- 2525 inet n – n – – smtpd
Note: 2525 can be changed to match the port that you wish to use. Also make sure you comment the line: ‘smtp inet n …..’ so that SMTP will run only on the new port. If you do not comment this line, then SMTP will run on 2 ports, one is port 25 (default) and another is the port that you are going to set (port 2525 in this case)
- Save the file and restart postfix.
service postfix restart
Now let’s check on which port, our SMTP service is running. Execute the same netstat command.
As we can see that our new SMTP port is now running.
- Now next step to add this port to the firewall so that it can accept incoming connections. As IPTABLES is installed on this server, we will add allow the port 2525 in this. Execute the below command to add the port and save the rule.
iptables -A INPUT -p tcp --dport 2525 -j ACCEPT
Verify the new port in iptables. Execute
It is now set. Further, you can also verify whether the new port is listening from outside or not using telnet.
Yes, it is listening. Now try to send an email and check whether you are able to send it or not.
mail -s "<Subject>" <Email Address> <<< "<Message>"
mail -s "test mail" email@example.com <<< "This is the body of the mail. SMTP is running on port 2525"
Sending of email is working fine.
I hope you like this post. Feel free to contact us, if you face any issue. Thank you. 🙂
My name is Shashank Shekhar. I am a DevOps Engineer, currently working in one of the best companies in India. I am having around 5 years of experience in Linux Server Administration and DevOps tools.
I love to work in Linux environment & love learning new things.
Powered by Facebook Comments