Intermediate LevelLinux Commands & SysAdmin
How is netcat (nc) used for network port scanning, file transfer, and banner grabbing?
❓ Interview Prompt: Explain Netcat (nc) utility, testing TCP/UDP port connectivity (nc -zv), banner grabbing, and simple file transfers.
'netcat' ('nc') is called the 'Swiss Army Knife' of networking utilities for reading and writing raw data across TCP and UDP sockets:
Use Cases:
•
Port Scanning / Connectivity Check: 'nc -zv 192.168.1.100 80 443 22'
•
Banner Grabbing: 'echo "" | nc -v -w 2 host 21'
•
Simple File Transfer: Receiver: 'nc -l 9000 > file.tar' | Sender: 'nc host 9000 < file.tar'.
Code Implementation Example
bash
# Test if remote port 5432 (PostgreSQL) is open and reachable (-z zero-I/O, -v verbose)
nc -zv db.internal 5432
# Test UDP port reachability (-u)
nc -zvu 192.168.1.1 53💡Testing TCP and UDP network port connectivity using netcat.
🎯 Interview Key Takeaway
Use nc -zv host port to quickly verify if remote TCP/UDP ports are listening and reachable through firewalls.
#netcat#nc#Port Scanning#Networking#Intermediate
Back to all Linux Commands & SysAdmin Questions→