What is nc Linux command?
The Linux nc command, also known as netcat, is a versatile networking tool used for reading and writing data across network connections using TCP or UDP. It can also be used for port scanning, transferring files, as a simple network server, and much more.
nc Syntax:
nc Options:
Option | Description |
---|---|
-h | Display help message and exit. |
-l | Used to specify to operate in listening mode. |
-p | Specify source port. |
-u | Use UDP instead of the default TCP. |
-v | Increase verbosity level. |
Parameters:
Parameter | Description |
---|---|
destination | Hostname or IP address of the target. |
port | Port number to connect to. |
nc Command Usage Examples:
Send Text to a Server
Sends the text “Hello, world!” to the server at example.com on port 80.
Check if a Remote Host is Reachable
Checks if the host example.com on port 443 is reachable using the -z
and -v
flags.
Transfer Files Over the Network
Starts a TCP server on port 1234 and saves the received data to the file received_file.txt.
Connect to a Remote SSH Server
Initiates a connection to the SSH server at example.com on port 22 using the -v
flag for verbosity.
Port Scanning
Scans ports 1 to 100 on the host example.com to check for open ports using the -z
and -v
flags.
How do I use nc in Linux?
To use the nc command in bash, execute the following command:
What is the purpose of the nc command?
The nc command, also known as netcat, is used for reading/writing data across network connections using TCP or UDP protocols.
How can I listen for incoming connections with nc?
To listen for incoming TCP connections on a specific port using nc, use the following command:
How can I perform a port scan using nc?
To perform a port scan on a specific target using nc, you can iterate over a range of ports with the following command:
How do I transfer files using nc?
To transfer a file from one host to another using nc, you can accomplish this by redirecting the file content through the network connection. On the receiving end, output the content to a specified file.
How can I check if a port is open using nc?
To check if a specific port is open on a target host, you can connect to it using nc and see if the connection is successful.
How do I create a simple web server using nc?
You can create a simple web server using nc to serve static files. For example, to serve a single HTML file, you can run the following command:
How can I use nc for chat-like communication between two hosts?
To establish a chat-like communication between two hosts using nc, run nc on both hosts in listening mode to read and write messages.
Applications of the nc command
- Port scanning
- Network debugging and exploration
- Transferring files
- Remote shell access
- Chat/Messaging
- Forwarding or redirecting ports
- Network daemon testing
- Proxying network connections