You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从远程设备经Windows Server访问NAT后的SQL Server 2014数据库?

Hey there! Let's break this down step by step since you're new to this—no worries, we'll get you sorted. Your setup is perfect for a reverse port forward (since your client can make outbound connections but can't receive inbound ones), and the server you mentioned will act as the middleman to bridge your remote device and the SQL Server client.

Below are three actionable solutions, from lightweight command-line tools to a beginner-friendly GUI option:

Socat is a flexible tool for network port forwarding, and it works great here. First, make sure you have Socat installed on both your server and client (Windows versions are available as pre-built binaries if you don't want to compile):

Step 1: Set up the server to listen on your specified port XXXX

On your server (if it's Linux, use your package manager to install Socat first; for Windows, open Command Prompt/PowerShell in the Socat folder):

# Linux server command
socat TCP-LISTEN:XXXX,fork TCP:localhost:14330

# Windows server command (same syntax, just run the socat.exe binary)
socat.exe TCP-LISTEN:XXXX,fork TCP:localhost:14330

This tells Socat to listen on port XXXX, and for every incoming connection, forward traffic to the server's local port 14330 (a temporary placeholder we'll use next).

Step 2: Have the client initiate a reverse connection to the server

On your Windows Server 2012 client (where SQL Server 2014 is running), run this Socat command to link your local SQL Server port (1433, default) to the server's XXXX port:

socat.exe TCP:YOUR_SERVER_IP:XXXX TCP:localhost:1433

This creates an outbound connection from the client to the server, effectively punching a hole through the client's firewall. Now any traffic sent to the server's port 14330 will be routed to the client's SQL Server.

Step 3: Connect from your remote device

Open your SQL client (SSMS on PC, any SQL app on Android) and connect to:

YOUR_SERVER_IP,XXXX

Use your SQL Server username and password, and you'll be connected directly to the client's database.

2. Windows PowerShell: No Extra Tools Needed

If you don't want to install Socat, you can use PowerShell's built-in .NET classes to create the same reverse forward:

Step 1: Start the server listener

On your server's PowerShell, run this script to listen on port XXXX and forward to local port 14330:

$listener = New-Object System.Net.Sockets.TcpListener('0.0.0.0', XXXX)
$listener.Start()
while ($true) {
    $client = $listener.AcceptTcpClient()
    $stream = $client.GetStream()
    $remoteStream = (New-Object System.Net.Sockets.TcpClient('localhost', 14330)).GetStream()
    $copy1 = $stream.CopyToAsync($remoteStream)
    $copy2 = $remoteStream.CopyToAsync($stream)
    Wait-Object $copy1 $copy2
    $client.Close()
}

Step 2: Initiate the client reverse connection

On your Windows Server 2012 client's PowerShell, run this to link local SQL port 1433 to the server's XXXX port:

$client = New-Object System.Net.Sockets.TcpClient('YOUR_SERVER_IP', XXXX)
$stream = $client.GetStream()
$localStream = (New-Object System.Net.Sockets.TcpClient('localhost', 1433)).GetStream()
$copy1 = $stream.CopyToAsync($localStream)
$copy2 = $localStream.CopyToAsync($stream)
Wait-Object $copy1 $copy2
$client.Close()

Step 3: Connect from remote device

Same as above—use YOUR_SERVER_IP,XXXX in your SQL client to access the database.

3. Teamviewer: Beginner-Friendly GUI Option

If command lines feel overwhelming, Teamviewer's built-in features make this super easy:

  • Install Teamviewer on both your Windows Server 2012 client and your remote device, log into the same Teamviewer account.
  • On your remote device, find the client in your Teamviewer device list, click More > VPN to enable Teamviewer's virtual private network.
  • Once the VPN is active, your remote device will be on the same virtual network as the client. Just connect to the client's local IP (e.g., 192.168.1.100,1433) in your SQL client.
  • Alternatively, if you use Teamviewer to remote into the client, go to Connection Settings > Local Port Forwarding and set up a rule to forward your remote device's port 1433 to the client's localhost:1433. Then connect to localhost:1433 on your remote device.

Critical Notes to Remember

  • Ensure your SQL Server is configured to allow remote connections: Open SQL Server Configuration Manager, enable TCP/IP protocol under SQL Server Network Configuration, and set it to listen on port 1433. Also, in SQL Server Management Studio, go to your instance's properties > Connections and check "Allow remote connections to this server".
  • If you want the client's reverse connection to stay active after a reboot, turn the Socat/PowerShell command into a Windows Service (use tools like NSSM for Socat, or create a scheduled task for PowerShell).
  • Double-check that your server's port XXXX is open to incoming connections (you mentioned it's accessible, so this should already be set).

内容的提问来源于stack exchange,提问作者Malto4

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:25:10