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
- Verify the current TCP port number of SQL Server
Syntax: netstat -tulpn
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>
- Changing the port requires restarting the SQL Server service
Syntax: systemctl restart mssql-server
- Let’s verify the SQL Server service is listening to which port number after restart
Syntax: netstat -tulpn
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
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
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
Verify the port number after restart of SQL Server service
Syntax: netstat -tulpn
Keep Learning!