Install SQL Server on CentOS and achieve public network access to the database through cpolar intranet penetration

Article directory

  • Preface
  • 1. Install sql server
  • 2. LAN test connection
  • 3. Install cpolar intranet penetration
  • 4. Map sqlserver to the public network
  • 5. Public network remote connection
  • 6. Fixed connection public network address
  • 7. Use a fixed public network address to connect

Foreword

In a few simple steps, you can install and deploy a sql server database in a Linux centos environment, and combine it with the cpolar intranet penetration tool to create a secure tunnel to map it to the public network, obtain the public network address, and remotely connect to the sqlserver database at home/company in a remote location. , without the need for a public IP, router, or cloud server.

1. Install sql server

Download the SQL Server 2022 (16.x) Red Hat repository configuration files:

sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2022.repo

Run the following command to install SQL Server:

sudo yum install -y mssql-server

Then wait for the installation to complete

image-20230418133937641

Once the package is installed, run mssql-conf setup using its full path, follow the prompts to set the SA password and select a version.

sudo /opt/mssql/bin/mssql-conf setup

The first three versions are licensed for free: Evaluation, Developer and Express. We choose the second one for testing.

image-20230418134248124

Then agree to the license terms and enter yes

image-20230418134351933

Select Chinese language

Then set the administrator password, remember the password, and don’t forget it

image-20230418134542902

After the installation is completed, it will start automatically

After completing the configuration, verify that the service is running:

systemctl status mssql-server

The default SQL Server port is 1433, TCP protocol. If you are using FirewallD for your firewall, you can use the following command:

sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent

Restart the firewall after setting up

sudo firewall-cmd --reload

At this point, the installation is complete.

Note: If you need to use the command line connection, you need to install the sql server command line tool when installing sqlserver. You can refer to the official tutorial: https://learn.microsoft.com/zh-cn/sql/linux/quickstart-install- connect-red-hat?view=sql-server-ver16

2. LAN test connection

Since I did not install the command line tool, we used a graphical tool to connect. Here we use navicat to test the connection. Enter the LAN IP address, enter the user name sa, the password set above, and click Test Connection. Connection successful appears

Click Database and check the default database.

image-20230418141543515

After logging in, you can see the default table information

image-20230418141621762

3. Install cpolar intranet penetration

In the above steps, we installed the sql server database on local Linux and the LAN test was ok.

Next, we install the cpolar intranet penetration tool. Through cpolar’s tcp public network address, we can easily access the sql server remotely without registering a domain name and purchasing a cloud server. cpolar supports http/https/tcp/tls/ftp protocols, does not limit traffic, and supports permanent free use.

cpolar official website: https://www.cpolar.com/

  • Use one-click script installation command
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
  • token authentication

Log in to the cpolar official website backend, click Verify on the left to view your authentication token, and then paste the token into the command line:

cpolar authtoken xxxxxxx

20230206171248

  • Add services to the system
sudo systemctl enable cpolar
  • Start cpolar service
sudo systemctl start cpolar

4. Map sqlserver to the public network

After successfully starting the cpolar service, we access the cpolar web UI management interface on the browser: Linux LAN IP address + 9200 port, log in using the cpolar email account (if you have not registered an account, go to the cpolar official website Register a)

After successful login, click Tunnel Management – Create Tunnel on the left dashboard to create a TCP protocol tunnel pointing to port 1433 of SQL Server:

  • Tunnel name: It can be customized. Be careful not to duplicate the existing tunnel name.
  • Protocol: tcp
  • Local address: 1433
  • Domain name type: Choose a random domain name for free
  • Region: Select China VIP

Click Create

Then open the online tunnel list, view and copy the public network address of the TCP protocol. [Note No need to copy tcp://]

image-20230418144336674

5. Public network remote connection

Open navicat or other connection tools, enter the public network address we obtained using the cpolar intranet penetration tool above, and the sqlserver username and password. Click Test Connection. If the connection is successful, it means success.

Note: The colon (:) in the public address needs to be changed to a comma (,)

image-20230418144828933

6. Fixed connection public network address

Since the above steps use a random temporary TCP port address, the generated public network address is a random temporary address, and the public network address will change randomly within 24 hours. Next, we configure a fixed TCP port address for it. This address will not change. After setting it, there will be no need to repeatedly modify the address every day, and the bandwidth speed will be increased at the same time.

Configuring a fixed TCP port address requires upgrading cpolar to the Professional Edition package or above.

  • Reserve a fixed tcp address

Log in to the cpolar official website backend, click Reserve on the left, and find the reserved TCP address. Let’s reserve a fixed TCP address for the remote SQL server:

  • Region: Select China vip
  • Description: Notes, customizable

Click Keep

image-20230418145833394

After the address is successfully reserved, the system will generate the corresponding fixed public address and copy it.

image-20230418151401097

  • Configure fixed tcp address

Log in to the cpolar web UI management interface on the browser, Linux LAN IP address + :9200 port.

Click Tunnel Management – Tunnel List on the left dashboard, find the remote sqlserver tunnel we created above, and click Edit on the right

image-20230418151434081

Modify the tunnel information and configure the successfully reserved fixed tcp address into the tunnel.

  • Port type: modified to fixed tcp port
  • Reserved tcp address: fill in the address successfully reserved by the official website

Click Update

image-20230418151510331

After the tunnel is successfully updated, click the status on the left dashboard – Online Tunnel List, and you can see that the public network address has been updated to a fixed TCP address.

image-20230418151535219

7. Use a fixed public network address to connect

Open the navicat connection tool, enter the fixed TCP address reserved by the official website, click Test Connection, and it will prompt that the connection is successful.

It should be noted that the colon (:) of the port after the public network address needs to be changed to a comma (,)

image-20230418152150422

Now this public network address will no longer change randomly. As long as the tunnel is kept online, we can use this fixed public network address to remotely connect to the sqlserver database on the LAN outside.

Reprinted from cpolar pole cloud article: Linux centos installs sql server database, combined with cpolar intranet penetration to achieve public network access – cpolar pole cloud