I had initially posted instructions on how to change the default Qmail port. However, an associate of mine pointed out the fallacy in my instructions. Changing the default Qmail port will prevent email from being delivered to your server as foreign mail servers will try to connect to your server on port 25 and if you change it, you won’t be able to receive email. I completely forgot about that little side effect when I posted this and have thus changed this post to only show how to configure an alternate port for Qmail.

A couple days ago I wrote about how to troubleshoot an email server when it isn’t working. This post isn’t necessarily follow-up to that, but more of a corollary. One of the things I didn’t mention in that post is what to do if you are running an email server and your ISP does not allow outgoing connections over port 25, the standard SMTP port. Many ISP’s have this policy to cust down on Spam sent through their servers, mine included. So when I tried to connect to my email the other day through Mozilla Thunderbird, I ran into a problem. I knew what I had to do. I had to configure Qmail to use an alternate port.

The first thing you will need to do is locate the service script for your email service. In my case, since I use Qmail with Plesk, my script was located at /etc/xinetd.d/smtp_psa. You will most likely have another one for SMTP over SSL named smtps_psa (or something close to). Next, you need to see what ports your server is currently listening on so you do not assign it to the same port as another service and cause problems. To do that, run the following command
netstat -tulpn | grep tcp That will show all current running services, the port their using, and filter out TCP only (so as not to see duplicate ports in the UDP section. You will be concerned with the column labeled “Local Address” as that will show the IP (0:0:0:0 or ::: means all IPs) and the port in use. Pick a random port number not in use for your SMTP configuration. I chose 2525.

How to configure Qmail to use an alternate port

To configure an alternate qmail port, you will need to first copy the default smtp service file to create an alternate configuration. I did this with the following code cp /etc/xinetd.d/smtp_psa /etc/xinetd.d/smtp_alt_psa You will then need to open your alternate service file and configure the alternate service name. Using a text editor of your choice (I like vi), type vi /etc/xinetd.d/smtp_alt_psa The first line should look something like service smtp That line will need to be changed so we don’t have two services with the same name. Hit i to enter insert mode and change the first line to read service smtp_alt Hit Esc, type :wq to write and quit.

We now need to edit the /etc/services file to set the port. Make sure the service name you use matches the service name you entered in the alternate configuration file above. I added these lines right below the original SMTP lines. Hit i again for insert mode and write in the two following lines smtp_alt 2525/tcp mail
smtp_alt 2525/udp mail
Your /etc/services file should look something like this smtp 25/tcp mail
smtp 25/udp mail
smtp_alt 2525/tcp mail
smtp_alt 2525/udp mail
Hit Esc, type :wq to write and quit. Now restart your email service. Again, here was my code to do that service xinetd restart Run the netstat -tulpn | grep tcp command again to verify that your email service is now listening on port 25 and 2525.

That’s all there is to it. You should now be able to connect through your email client to your server on your alternate port. Questions? Comments? Problems? Post them below and I’ll do my best to help out.

For more help on using the vi/vim text editor, visit our Linux command line cheat sheet with extensive information on using vi.

Check out these Related Posts