Use PowerShell to check for open ports

Sometime servers need to communicate with one another over specific ports. When you attempt to connect one server to the next the connection fails with a vague response like, “connection failed”. To validate the port is open you need to find from the applications administration guide what ports are need and then test the connection using the Test-NetConnection command.

Test-NetConnection -ComputerName 192.168.1.1 -Port 443
Test-NetConnection -ComputerName hostname -Port 443

PS C:\Windows\system32> Test-NetConnection -ComputerName MyServName-01 -Port 3741
WARNING: TCP connect to (192.168.2.10 : 3741) failed

ComputerName           : MyServName-01
RemoteAddress          : 192.168.2.10
RemotePort             : 3741
InterfaceAlias         : Ethernet0 2
SourceAddress          : 192.168.2.118
PingSucceeded          : True
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded       : False

PS C:\Windows\system32>

As we can see from the output of the command “Test-NetConnection -ComputerName MyServName-01 -Port 3741” we are testing the connection from the source server, where we run the command from, to the remote server “MyServName-01” over the port of 3741. The ping is successful, but the port connection fails, so we know that the network is connected, but we need to check why the port is not open between servers. This can be a firewall issue, either on the servers itself or sitting in the middle on the network between the two servers. Also, depending on the server and the applications running, will determine how to track down the closed port and to then open that port. Don’t forget to validate settings on both servers.

Leave a Reply

Your email address will not be published. Required fields are marked *