๐ Table of Contents
- Overview & Prerequisites
- Installation Guide
- Netcat (nc) Testing
- hping3 Advanced Testing
- Testing Scenarios
- Performance Benchmarking
- Troubleshooting
- Security Testing
- Best Practices
Overview
This guide covers essential techniques for testing your own servers using two powerful command-line tools:
Tools Covered
๐ง netcat (nc)
Swiss army knife for network connections - excellent for basic connectivity tests and data transfer
๐ hping3
Advanced packet crafting and network testing tool for sophisticated testing scenarios
โ ๏ธ Important Safety Notice
Always test only servers you own or have explicit permission to test. Unauthorized testing may violate terms of service or local laws.
Prerequisites
- Root or sudo access on your test machine
- Basic understanding of TCP/IP networking
- Target servers that you own and have permission to test
Installation
Ubuntu/Debian
sudo apt-get updatesudo apt-get install netcat-openbsd hping3
CentOS/RHEL/Fedora
# or for newer versions:sudo yum install nc hping3sudo dnf install nc hping3
macOS
# netcat is pre-installedbrew install hping
Netcat (nc) Testing
Basic Port Connectivity Testing
Test if a port is open
# Basic TCP connection testnc -zv server_ip port# Test multiple portsnc -zv 192.168.1.100 80# UDP port testnc -zv 192.168.1.100 80-90nc -zuv 192.168.1.100 53
Test port ranges
# Scan ports 1-1000# Common service portsnc -zv server_ip 1-1000nc -zv server_ip 21,22,23,25,53,80,110,143,443,993,995
Service Banner Grabbing
HTTP service testing
# Connect to HTTP server# Then type: GET / HTTP/1.1 followed by two newlines # Automated HTTP testnc server_ip 80echo -e "GET / HTTP/1.1\r\nHost: server_ip\r\n\r\n" | nc server_ip 80
SSH banner grab
# Server will respond with SSH version bannernc server_ip 22
File Transfer Testing
Simple file server
# On receiving server# On sending machinenc -l -p 8080 > received_file.txtnc server_ip 8080 < file_to_send.txt
hping3 Advanced Testing
Basic Connectivity Tests
ICMP ping alternative
# Standard hping3 ping# TCP ping to specific porthping3 -c 4 server_ip# UDP pinghping3 -S -p 80 -c 4 server_iphping3 -2 -p 53 -c 4 server_ip
Firewall and Filter Testing
Test firewall rules
# Test if TCP port is filtered# Test different TCP flagshping3 -S -p 443 -c 3 server_ip# FIN flaghping3 -F -p 80 -c 3 server_ip# ACK flaghping3 -A -p 80 -c 3 server_ip# PUSH flaghping3 -P -p 80 -c 3 server_ip
Load Testing
๐ Controlled Testing
Be extremely careful with flood tests. Start with low rates and monitor your server's response.
Connection rate testing
# Controlled rate SYN test# 1000 microsecond interval # Test connection establishment ratehping3 -S -p 80 -i u1000 server_iphping3 -S -p 80 -i u100 -c 1000 server_ip
Comprehensive Testing Scenarios
Web Server Testing
# 1. Basic connectivity# 2. HTTP response testnc -zv web_server 80 443# 3. SSL/TLS port testecho -e "GET / HTTP/1.1\r\nHost: web_server\r\n\r\n" | nc web_server 80# 4. Load response testnc -zv web_server 443hping3 -S -p 80 -i u1000 -c 100 web_server
Database Server Testing
# MySQL/MariaDB# PostgreSQLnc -zv db_server 3306# Redisnc -zv db_server 5432nc -zv db_server 6379# MongoDBecho "PING" | nc db_server 6379nc -zv db_server 27017
SSH Server Testing
# Basic connectivity# Banner grabnc -zv ssh_server 22# Test SSH with different algorithmsnc ssh_server 22hping3 -S -p 22 -c 3 ssh_server
Performance Benchmarking
Bandwidth Testing
Simple bandwidth test using nc
# Server side:# Client side:nc -l -p 8080 | pv > /dev/nulldd if=/dev/zero bs=1M count=1000 | pv | nc server_ip 8080
Latency Testing
# Round-trip time measurement# TCP connection timehping3 -c 100 -i u10000 server_ip | grep round-triphping3 -S -p 80 -c 10 server_ip | grep round-trip
Troubleshooting Common Issues
Connection Timeouts
# Increase timeout# Test with different protocolsnc -w 10 server_ip port# ICMPhping3 -1 server_ip# UDPhping3 -2 -p 53 server_ip# TCP SYNhping3 -S -p 80 server_ip
Firewall Detection
# Test for stateful firewall# Should be dropped if stateful # Test for port filteringhping3 -A -p 80 server_ip# Test non-standard porthping3 -S -p 12345 server_ip
Best Practices
๐ก๏ธ Safety Guidelines
- Always test only servers you own or have explicit permission to test
- Start with gentle tests before aggressive ones
- Monitor server resources during testing
- Have rollback plans for any configuration changes
- Document baseline performance before testing
Testing Methodology
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
๐ก Pro Tips
- Don't test production servers during peak hours
- Avoid overwhelming servers with excessive connections
- Be cautious with flood tests - they can cause legitimate DoS
- Always check legal compliance for your testing activities
- Don't leave nc listeners running indefinitely