Master nc and hping3 for Comprehensive Server Analysis
Learn how to effectively test your own servers using netcat and hping3 commands. This comprehensive guide covers connectivity testing, performance analysis, and security validation.
This guide covers essential techniques for testing your own servers using two powerful command-line tools:
Swiss army knife for network connections - excellent for basic connectivity tests and data transfer
Advanced packet crafting and network testing tool for sophisticated testing scenarios
Always test only servers you own or have explicit permission to test. Unauthorized testing may violate terms of service or local laws.
sudo apt-get update sudo apt-get install netcat-openbsd hping3
sudo yum install nc hping3 # or for newer versions: sudo dnf install nc hping3
# netcat is pre-installed brew install hping
# Basic TCP connection test nc -zv server_ip port nc -zv 192.168.1.100 80 # Test multiple ports nc -zv 192.168.1.100 80-90 # UDP port test nc -zuv 192.168.1.100 53
# Scan ports 1-1000 nc -zv server_ip 1-1000 # Common service ports nc -zv server_ip 21,22,23,25,53,80,110,143,443,993,995
# Connect to HTTP server nc server_ip 80 # Then type: GET / HTTP/1.1 followed by two newlines # Automated HTTP test echo -e "GET / HTTP/1.1\r\nHost: server_ip\r\n\r\n" | nc server_ip 80
nc server_ip 22 # Server will respond with SSH version banner
# On receiving server nc -l -p 8080 > received_file.txt # On sending machine nc server_ip 8080 < file_to_send.txt
# Standard hping3 ping hping3 -c 4 server_ip # TCP ping to specific port hping3 -S -p 80 -c 4 server_ip # UDP ping hping3 -2 -p 53 -c 4 server_ip
# Test if TCP port is filtered hping3 -S -p 443 -c 3 server_ip # Test different TCP flags hping3 -F -p 80 -c 3 server_ip # FIN flag hping3 -A -p 80 -c 3 server_ip # ACK flag hping3 -P -p 80 -c 3 server_ip # PUSH flag
Be extremely careful with flood tests. Start with low rates and monitor your server's response.
# Controlled rate SYN test hping3 -S -p 80 -i u1000 server_ip # 1000 microsecond interval # Test connection establishment rate hping3 -S -p 80 -i u100 -c 1000 server_ip
# 1. Basic connectivity nc -zv web_server 80 443 # 2. HTTP response test echo -e "GET / HTTP/1.1\r\nHost: web_server\r\n\r\n" | nc web_server 80 # 3. SSL/TLS port test nc -zv web_server 443 # 4. Load response test hping3 -S -p 80 -i u1000 -c 100 web_server
# MySQL/MariaDB nc -zv db_server 3306 # PostgreSQL nc -zv db_server 5432 # Redis nc -zv db_server 6379 echo "PING" | nc db_server 6379 # MongoDB nc -zv db_server 27017
# Basic connectivity nc -zv ssh_server 22 # Banner grab nc ssh_server 22 # Test SSH with different algorithms hping3 -S -p 22 -c 3 ssh_server
# Server side: nc -l -p 8080 | pv > /dev/null # Client side: dd if=/dev/zero bs=1M count=1000 | pv | nc server_ip 8080
# Round-trip time measurement hping3 -c 100 -i u10000 server_ip | grep round-trip # TCP connection time hping3 -S -p 80 -c 10 server_ip | grep round-trip
# Increase timeout nc -w 10 server_ip port # Test with different protocols hping3 -1 server_ip # ICMP hping3 -2 -p 53 server_ip # UDP hping3 -S -p 80 server_ip # TCP SYN
# Test for stateful firewall hping3 -A -p 80 server_ip # Should be dropped if stateful # Test for port filtering hping3 -S -p 12345 server_ip # Test non-standard port
1. Baseline establishment: Record normal server behavior
2. Incremental testing: Start with simple tests, increase complexity
3. Documentation: Keep detailed logs of all tests and results
4. Validation: Verify server functionality after each test phase
5. Cleanup: Remove any test files or temporary configurations