Test if a remote port is reachable
Read-only
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Checks whether a TCP port on a remote host accepts connections, useful for diagnosing firewalls, security groups, and whether a service is up.
networkportconnectivityfirewall
Parameters
Remote hostname or IP address to test.
Remote TCP port to test.
Commands
Attempt a TCP connection with a 5-second timeout and report the result
nc -vz -w 5 <host> <port>Verification
nc -vz -w 5 <host> <port>A "succeeded" message means the port is open; a timeout or refusal means it is closed or filtered.
Undo
Not undoable
This recipe only opens and closes a test connection and changes nothing.
Pitfalls
- A timeout usually means a firewall drops packets silently, while "connection refused" means the host was reached but nothing listens on the port.
- Some load balancers accept TCP connections even when the backend service is unhealthy, so a successful connect does not guarantee the application works.
- The verification command uses macOS/Linux syntax; on Windows use "Test-NetConnection -ComputerName {{host}} -Port {{port}}" and check TcpTestSucceeded.