Menu
User

DropVPS Team

Writer: Cooper Reagan

Change Default Ports for Common Services (SSH, Nginx, MySQL)

Change Default Ports for Common Services  (SSH, Nginx, MySQL)

Publication Date

12/31/2025

Category

Articles

Reading Time

1 Min

Table of Contents

Changing default service ports reduces automated attacks and avoids conflicts when running multiple services on a VPS.

Step 1: Change the SSH Port

Edit the SSH configuration file.

sudo nano /etc/ssh/sshd_config

Find and change the port value.

Port 2222

Save the file and restart SSH.

sudo systemctl restart ssh

Allow the new port in the firewall before disconnecting.

sudo ufw allow 2222/tcp

Step 2: Change the Nginx Port

Edit the default Nginx server block.

sudo nano /etc/nginx/sites-available/default

Modify the listen directive.

listen 8080;

Test and reload Nginx.

sudo nginx -t
sudo systemctl reload nginx

Step 3: Change the MySQL Port

Edit the MySQL configuration file.

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Set a custom port.

port = 3307

Restart MySQL.

sudo systemctl restart mysql

Step 4: Update Firewall Rules

Allow the new ports and optionally close the old ones.

sudo ufw allow 8080/tcp
sudo ufw allow 3307/tcp

Step 5: Verify Port Changes

Confirm that services are listening on new ports.

sudo ss -tulnp

You may also want to review this related article: Change Hostname in Linux Easily and Quickly

Optional Step: Update Client Configurations

Remember to update applications and connection strings to use the new ports.

Linux VPS
U
Loading...

Related Posts