Node.js与SQL Server连接超时:疑为防火墙拦截及规则配置咨询
That ETIMEOUT error you're hitting is a dead giveaway that your connection request is getting blocked before it even reaches the SQL Server instance. Let's walk through how to tweak firewall rules on both your local machine and the server side to get this working.
1. Configure Firewall on the SQL Server Host Machine
If the SQL Server runs on a physical server or VM you control, here's how to open the default SQL Server port (1433):
Windows Server Firewall
- Open Windows Defender Firewall with Advanced Security
- Navigate to Inbound Rules > New Rule
- Select Port as the rule type, then click Next
- Choose TCP, enter
1433in the "Specific local ports" field, click Next - Pick Allow the connection, then click Next
- Check the network profiles (Domain, Private, Public – adjust based on your environment), click Next
- Name the rule something like "Allow SQL Server TCP 1433", add a quick description if you want, then click Finish
Linux Server Firewall (UFW Example)
For Linux-hosted SQL Server, run these commands to open the port:
sudo ufw allow 1433/tcp sudo ufw reload
2. Cloud Provider Firewall Rules (If Using AWS/Azure/GCP)
If your SQL Server is on a cloud platform, you’ll need to update the network security group (NSG) or firewall rules specific to your provider:
AWS EC2
- Go to your EC2 instance’s Security Groups
- Add an inbound rule:
- Type: Custom TCP
- Port Range: 1433
- Source: Your local machine’s public IP (use
0.0.0.0/0only for testing – never leave this in production)
- Save the rule
Azure VM/SQL Database
- For Azure VMs: Go to Networking > Inbound port rules and add a rule allowing TCP 1433 from your IP
- For Azure SQL Database: Navigate to Firewalls and virtual networks and add your local IP to the "Allowed IP addresses" list
GCP Compute Engine
- Go to your VM’s Firewall settings
- Create a new firewall rule:
- Direction: Ingress
- Targets: Your VM instance
- Source IP ranges: Your local IP
- Protocols and ports: Specified protocols and ports > TCP:1433
- Save the rule
3. Local Machine Firewall (If Applicable)
Sometimes your local firewall blocks outbound connections to port 1433. To check:
- On Windows: Go to Windows Defender Firewall > Advanced Settings > Outbound Rules and make sure there’s no rule blocking TCP 1433
- On Linux: Run
sudo ufw statusto verify outbound traffic to 1433 is allowed
4. Verify the Connection
After setting up the rules, test if the port is open using telnet or nc (netcat):
telnet 35.200.150.88 1433 # Or with netcat nc -zv 35.200.150.88 1433
If you get a successful connection response, your firewall rules are working – go ahead and retry your Node.js connection.
Quick reminder: If you’re using a non-default port for SQL Server, replace 1433 with your custom port in all the steps above.
内容的提问来源于stack exchange,提问作者Tushar Kshirsagar

