Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to change SSH, SMTP, cPanel Port Number in Linux  (Read 8137 times)

0 Members and 1 Guest are viewing this topic.

sumesh

  • Guest
How to change SSH, SMTP, cPanel Port Number in Linux
« on: October 26, 2013, 07:28:31 am »
Hi All,

This is a simple topic, but a very important one

Step 1

As root, use your favorite text editor (vi or vim) to edit the sshd configuration file.

          vi /etc/ssh/sshd_config

Step 2

Edit the line which states 'Port 22'. But before doing so, you'll want to read the note below. Choose an appropriate port, also making sure it not currently used on the system.

          # What ports, IPs and protocols we listen for
           Port 50683

Note: The Internet Assigned Numbers Authority (IANA) is responsible for the global coordination of the DNS Root, IP addressing, and other Internet protocol resources. It is good practice to follow their port assignment guidelines. Having said that, port numbers are divided into three ranges: Well Known Ports, Registered Ports, and Dynamic and/or Private Ports. The Well Known Ports are those from 0 through 1023 and SHOULD NOT be used. Registered Ports are those from 1024 through 49151 should also be avoided too. Dynamic and/or Private Ports are those from 49152 through 65535 and can be used. Though nothing is stopping you from using reserved port numbers, our suggestion may help avoid technical issues with port allocation in the future.

Step 3

Switch over to the new port by restarting SSH.

          /etc/init.d/ssh restart

Step 4

Verify SSH is listening on the new port by connecting to it. Note how the port number now needs to be declared.
ssh username@hostname.com -p 50683


##############
# SMTP-Postfix
##############
How to change SMTP port on Postfix server

Open the file /etc/postfix/master.cf

vim /etc/postfix/master.cf

-------------------------------------------------------------------
#Comment default line as below.
#smtp      inet  n       -       n       -       -       smtpd
#Add new line with port as you like as below.
9485      inet  n       -       n       -       -       smtpd
-------------------------------------------------------------------

Restart the postfix service use the following command

/etc/init.d/postfix restart


And configue you SMTP as

Hostname            Port no   Username  Password   
SMTP.domain.com     9485       abc      passwd


######
# Exim
######
Exim

If you have WHM/cPanel, you can simply go into Service Manager and change the port there. Be sure to enable 'Exim on Another Port'.

Otherwise, modify the following file, using your favourite text editor:
/etc/exim.conf

You will need to add these lines, replacing 26 by 587 if desired:
daemon_smtp_ports = 26
acl_smtp_rcpt = check_recipient
acl_smtp_data = check_message


#######
# Qmail
#######
QMail

You will need to modify the following file:

/etc/services

Add the following line, replacing the <port> with the actual port:

smtp_alt <port>/tcp # new SMTP port

If you are running xinetd as a super-server, you will need to follow these extra instructions:

First, make a backup copy of smtp_psa by using this command:

cp /etc/xinetd.d/smtp_psa /etc/xinetd.d/smtp_psa_alt

Then edit the file /etc/xinetd.d/smtp_psa and add the following line:

service smtp_alt

Then restart xinetd using the following command:

/tc/init.d/xinetd restart


#############
# Qmail-Plesk
#############
Configure qmail to use alternate SMTP port 26 on linux plesk server.

On dedicated servers some time port 25 wont work due to port 25 block at ISP end.
follow the below steps to change SMTP port on your plesk dedicated (linux) server to 26

Login to server as root user.
root# cd /etc/xinetd.d

root# ls -l | grep smtp*

root# cat smtp_psaservice smtp
{
socket_type = stream
protocol = tcp
wait = no
disable = no
user = root
instances = UNLIMITED
server = /var/qmail/bin/tcp-env
server_args = /usr/sbin/rblsmtpd -r bl.spamcop.net /var/qmail/bin/relaylock /var/qmail/bin/qmail-smtpd /var/qmail/bin/smtp_auth /var/qmail/bin/true /var/qmail/bin/cmd5checkpw /var/qmail/bin/true
}


root# vi /etc/services

Add the below two lines
============
smtp_psa_new 26/tcp mail
smtp_psa_new 26/udp mail
============

root# cp smtp_psa smtp_psa_new

Change the service line in the new file “smtp_psa_new” to be this:

service smtp_psa_new
{
socket_type = stream
protocol = tcp
wait = no
disable = no
user = root
instances = UNLIMITED
server = /var/qmail/bin/tcp-env
server_args = /usr/sbin/rblsmtpd -r bl.spamcop.net /var/qmail/bin/relaylock /var/qmail/bin/qmail-smtpd /var/qmail/bin/smtp_auth /var/qmail/bin/true /var/qmail/bin/cmd5checkpw /var/qmail/bin/true
}

root# /etc/init.d/xinetd restart

And you should see smtp listening on ports 25, and 26:

root# netstat -anp | grep xinetd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6989/xinetd
tcp 0 0 0.0.0.0:26 0.0.0.0:* LISTEN 6989/xinetd


you check whether the port 25 and 26 are working or not using following commands.

netstat -nap | grep :25
netstat -nap | grep :26

Done.


#######
cPanel service
#######

You can modify the file at /var/cpanel/cpanel.config

Change the entry port=2082 in this file

Run the below commands
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings

/etc/init.d/httpd restart
« Last Edit: October 26, 2013, 09:14:19 am by Admin »