Checking Port Availability Using Netcat (nc)

Netcat (nc) is a powerful networking tool that can be used for a variety of tasks, such as scanning ports, connecting to remote systems, and troubleshooting network issues. This note explains how to use nc to check if a specific port (e.g., MySQL's default port) is open on your local machine or a remote server.

Command Breakdown: nc -zv 127.0.0.1 3306

1. nc:

2. -z (Scan for Open Ports):

3. -v (Verbose Mode):

4. 127.0.0.1:

5. 3306:

Example Scenarios:

1. MySQL is Running:

If MySQL is running on port 3306, you will see:

Connection to 127.0.0.1 3306 port [tcp/mysql] succeeded!

This means that MySQL is accepting connections on port 3306.

2. MySQL is Not Running:

If MySQL is not running on port 3306, you will see:

nc: connect to 127.0.0.1 port 3306 (tcp) failed: Connection refused

This means either:

Checking Multiple Ports:

You can also check multiple ports at once by listing them after the IP address. For example:

nc -zv 127.0.0.1 3306 8080 443

This command will check if ports 3306 (MySQL), 8080 (HTTP), and 443 (HTTPS) are open on 127.0.0.1.



Written by A.M. Rinas