Remotely connect to the MongoDB database on Windows [no public network IP]

Reprinted from the article of remote intranet penetration: Remote connection to MongoDB database through the public network [Intranet penetration]

foreword

MongoDB is a database based on distributed file storage. Written by C++ language. It aims to provide scalable high-performance data storage solutions for WEB applications.

MongoDB is a product between relational databases and non-relational databases. It is the most functional among non-relational databases and most similar to relational databases. The data structure it supports is very loose, which is a bson format similar to json, so it can store more complex data types. The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is somewhat similar to object-oriented query language. It can almost realize most of the functions similar to single-table query of relational database, and it also supports indexing of data.

A few simple steps to achieve remote access to MongoDB.

1. Install the database

Open the MongoDB official website https://www.mongodb.com/try/download/community , here is the windows version as an example.

20230220114401

After downloading, double-click to install. At this point in the installation, you must click complate to set the account password

20230220114402

After entering, you can set a password, then click next, or just click next to install

20230220114403

After installation, we use the connection tool to test the connection, here we use navicat connection

20230220114404

2. Intranet penetration

After the local connection is fine, the database can only be accessed in the local area network at present, but we can use the cpolar intranet penetration tool to map the MongoDB database in the intranet to the public network to achieve remote access without the need for public network IP, and also No need to set up a router.

2.1 Install cpolar intranet penetration

Go to the download page of cpolar official website, download the windows installation package to the local and unzip it all the way to install by default

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

20230220114405

2.2 Create a tunnel map

After cpolar is successfully installed, double-click to open cpolar [or access the local port 9200 on the browser: 127.0.0.1:9200], use the cpolar email account to log in to the web UI management interface, if you have not registered a cpolar account, click Register for free, and you will be prompted Go to cpolar official website to register an account.

20230220114406

After successful login, click Tunnel Management on the left dashboard - Create Tunnel, and create a tcp protocol tunnel pointing to the local port 27017:

  • Tunnel name: can be customized, be careful not to duplicate the existing tunnel name
  • protocol: tcp
  • Local address: 27017
  • Domain name type: choose a random domain name for free
  • Region: Default China top

click create

20230220114407

After the tunnel is successfully created, click on the status on the left - online tunnel list, you can see that the tunnel just created has generated a corresponding public network address, copy it

20230220114408

2.3 Test remote connection with random public network address

Open navicat, enter the tcp public network address: 3.tcp.cpolar.top port number 11249, then click Test Connection, and the connection is successful.

20230220114409

3. Configure a fixed TCP port address

Since the tunnel created above is a random address tunnel, the address will change within 24 hours. In order to make the connection more stable, we can configure a fixed tcp connection address for it.

It should be noted that to configure a fixed TCP port address, cpolar needs to be upgraded to a professional package or above.

3.1 Reserve a fixed public network TCP port address

Log in to the cpolar official website, click Reserve on the left, and select the reserved TCP address. Let's first reserve a fixed port address for the remote MongoDB.

  • Region: Select China VIP
  • Description: Remarks, which can be customized

Click to keep

20230220114411

After the address is successfully reserved, the system will generate a corresponding fixed public network address and copy it down
20230220114412

3.2 Configure a fixed public network TCP port address

Access port 9200 on the browser, http://127.0.0.1:9200/ , log in to the cpolar web ui management interface, click Tunnel Management on the left dashboard - Tunnel List, find the MongoDB tunnel, and click Edit on the right

20230220114413

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 successfully reserved address

click update

20230220114414

After the tunnel is successfully updated, click the status on the left dashboard - the list of online tunnels, find the tunnel to be edited, and you can see that the public network address has been updated to a fixed tcp address.

20230220114415

3.3 Test public network remote access with fixed address

Test remote MongoDB using a fixed TCP port address, open navicat again, and use a fixed tcp address to connect

20230220114416

Guess you like

Origin blog.csdn.net/qq_41250372/article/details/130211910