How to change default port for SQL Server on Linux
By: Rajendra Gupta | Comments (2) | Related: More > SQL Server on Linux
Microsoft released SQL Server to run on Linux servers. To secure the database environment, DBA's often change the SQL Server port from its default port 1433 to another available port number. In this tip we will see how we can make this change for SQL Server on Linux.
In a previous tip, Installing SQL Server vNext CTP1 on Red Hat Linux 7.2, we installed SQL Server on Red Hat Linux. Once we have installed SQL Server on Linux, we can check the service status using the below command.
#check the status of mssql-server service. systemctl status mssql-server
As we can see above, SQL Server is running on the default port 1433. In this tip we will explore how to change the port number.
Configuration of SQL Server on Linux with mssql-conf
As per Microsoft documentation, mssql-conf is a configuration script that installs with SQL Server vNext CTP 1.2 for Red Hat Enterprise Linux, SUSE Linux Enterprise Server, and Ubuntu. We can use this utility to set the following parameters:
- TCP port: Change the port where SQL Server will listen for connections.
- Default data directory: Change the directory for new SQL Server database data files (.mdf).
- Default log directory: Changes the directory for new SQL Server database log (.ldf) files are created.
- Default dump directory: Change the directory where SQL Server will deposit memory dumps and other troubleshooting files by default.
- Default backup directory: Change the directory where SQL Server will send backup files by default.
- Set traceflags: Set the trace flags that the service is going to use.
- Set collation: Set a new collation for SQL Server on Linux.
Change default SQL Server TCP Port
Now suppose we want to change the default TCP Port of SQL Server from 1433 to 5500, follow the below steps.
1. Run the mssql-conf script as root with the "set" command for "tcpport". In the below query I specified tcpport 5500, but you can use whatever available port you would like.
sudo /opt/mssql/bin/mssql-conf set tcpport 5500
2. Restart the SQL Server service.
As we can see above, after we apply new tcpport, it gives notification to restart SQL Server service.
sudo systemctl restart mssql-server
3.We may need to run the below commands to open the SQL Server port on the firewall on the Linux server.
sudo firewall-cmd --zone=public --add-port=5500/tcp --permanent sudo firewall-cmd --reload
4. Check the SQL Server service to the verify port has changed.
We can see now the SQL service is running on port 5500.
- In another tip we will explore how to change the default location of data files and log files.
- Read more SQL Server on Linux Tips
About the author
View all my tips