Change the TCP Port on SQL Server on Linux

When you install SQL Server on Linux, the default instance is setup to listen on port 1433. Most of the companies don’t follow the default port because of vulnerability issue. In this case, you may consider using any other ports instead of the default port 1433. In this article, I will discuss how to change the default TCP port number on SQL Server on Linux.

Change the default port of SQL Server on Linux

  • Connect your Linux machine as a root user

Syntax: sudo -i

01connectasrootuser

  • Verify the current TCP port number of SQL Server

Syntaxnetstat -tulpn

02verifythecurrentportofsqlserver

Note: If you are not connected as a root user, you won’t see the program name.
  • Now, let’s change the default port to some other ports. To demonstrate it, I shall be changing the port from 1433 to 2311 by running following command;

Syntax: /opt/mssql/bin/mssql-conf set tcpport <newport>

03changethedefaultportofsqlserveronlinux

  • Changing the port requires restarting the SQL Server service

Syntax: systemctl restart mssql-server

04restartthesqlserverservice

  • Let’s verify the SQL Server service is listening to which port number after restart

Syntaxnetstat -tulpn

05verifythechangedport

The above output confirms that the SQL Server TCP port number has been changed from 1433 to 2311.

  • Connect to SQL Server Instance using the new port number

06connectsqlserver

 

Reset to the default TCP port

There are two ways to reset to the default TCP port number. You can follow the above steps to reset the SQL Server service to listen default port 1433, or you can fire below command to unset it.

Syntax: /opt/mssql/bin/mssql-conf unset tcpport

07unsettodefaulttcpport

Although it didn’t prompt you to restart the SQL Server service, you have to reset the service to get the effect of the default TCP port number.

Syntax: systemctl restart mssql-server

04restartthesqlserverservice

Verify the port number after restart of SQL Server service

Syntaxnetstat -tulpn

02verifythecurrentportofsqlserver

Keep Learning!

Leave a comment

Your email address will not be published. Required fields are marked *