Wednesday, June 29, 2016

How to open Exim port 26 on cPanel via SSH

It's no secret that ISP’s will sometimes limit traffic on the common SMTP ports (25 & 587). The result is that clients will constantly contact you because they are unable to send mail. The fix is normally to switch to the alternate port i.e. from port 25 to 587 and vice-versa. This however is only a temporary fix and the client will soon contact you (slightly more frustrated) again with the same problem.
Luckily, cPanel makes it easy to add additional ports for Exim to listen on. By opening for example port 26 on the server and asking your client to use that port instead, your "outgoing mail issue" calls will soon be a thing of the past.
In WHM, it is as simple as logging in, navigating to Service Manager and enabling the “Exim Mail Server (on another port)” option. But what if you have multiple servers? If that is the case, it is easier to do this via the command line (SSH) since you can create a script  to open the port throughout your entire cPanel cluster.
This is how you open port 26 via SSH on a cPanel server:

Step 1

Edit your exim.conf file
vi /etc/exim.conf
Find the following line. Note that the port numbers may not be in this order.
daemon_smtp_ports = 587 : 25 : 465
Now add port 26 as follows
daemon_smtp_ports = 587 : 25 : 465 : 26
Once changed, save and exit the file.

Step 2

Before you can rebuild the exim config, you need to add this entry to exim.conf.local as well, otherwise cPanel will simply override this entry when you rebuild the config.
vi /etc/exim.conf.local
Add the line to the file under the @CONFIG@ section
daemon_smtp_ports = 587 : 25 : 465 : 26
Save and exit the file

Step 3

Rebuild exim config and restart the exim service
/usr/local/cpanel/scripts/buildeximconf
service exim restart

Step 4

Open port 26 on your server firewall. This will mostly be CSF on cPanel servers.
vi /etc/csf/csf.conf
Find the “Allow incoming TCP ports” section and add port 26 as per the example below.
# Allow incoming TCP ports
TCP_IN = "20,21,25,26,53,80,110,143
Save the config file and restart CSF
csf –r
That’s it, Exim will now listen on port 26. To ensure that the port is open, you can telnet from another server to port 26 on the server where you opened the port as follows.
telnet server_ip 26
You should see something like this.
Trying server_ip...
Connected to server_ip.
Escape character is '^]'.
220-server_ip ESMTP Exim 4.87 #1 Mon, 06 Jun 2016 08:57:49 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
Although the method in this tutorial will take much longer on a single server as supposed to doing it via WHM, it will be MUCH faster if you have to do it on 100 servers via a simple bash script.
Enjoy your reduced client contact!

No comments:

Post a Comment