Menu & Search
Testing Connectivity to Remote Server Ports with PowerShell

Testing Connectivity to Remote Server Ports with PowerShell

All admins need a tool to test connectivity to remote servers on TCP ports. In Windows, this is commonly done using PuTTy or PowerShell.

This post a note on my favorite way of testing remote TCP connections in Windows, which is using PowerShell:
# Check a Port is Open (Pre Win08/Svr2012)
# Check a Port is Open (Test-NetConnection)
# Troubleshooting

Important ports to remember in the life of a DBA may include:
# SQL Server (1433)
# RedShift (5439)
# PostgreSQL (5432)
# MySQL (3306)
# Oracle (1521)

Check a Port is Open (Pre Win08/Svr2012)

This is for when you’re on a legacy server running an old version of PowerShell. I managed to spawn a Windows Server 2008 R2 box from the AWS Marketplace for this test.

# Check a port is open (pre Win08/Svr2012).
$Ipaddress= Read-Host "Enter the IP address:"
$Port= Read-host "Enter the port number to access:"
$t = New-Object Net.Sockets.TcpClient
    {"Port $Port is operational."}
else {"Port $Port is closed."}

Enter IP address and port number when prompted.  

Test-NetConnection PowerShell

Below is an example of no connectivity. The server I was testing didn’t have SQL Server installed, so nothing listening on that port.

Check a Port is Open (Test-NetConnection)

I use Test-NetConnection very often… It’s built-in to recent editions of Window Server and easy to use.

Note:: Traffic might get blocked by or go through things like Local/Internal/External Firewalls, VPNs, NAT Gateways, Routing, AWS Security Groups/NACLs, Load Balancers & whatever else… Diagnosing connectivity issues can be very complex. This is a simple test and might not get picked up by network logs at times. You might have to try genuine traffic, i.e. the task you were needing the port open for, running a SQL extract in this case as it’s port 1433.

Test-NetConnection -ComputerName -Port 1433

You can use IP addresses for the -ComputerName parameter.


If connectivity is failing, a few things to check include:
# There has to be something ‘listening’ on the remote server port.
# Network (Inc. DNS) configurations & Security Groups.
# Firewalls (at the Infrastructure level or local host config).