| name | shell-networking |
| description | Production-grade shell networking - curl, ssh, ports, debugging |
| sasmp_version | 1.3.0 |
| bonded_agent | 05-networking |
| bond_type | PRIMARY_BOND |
| version | 2.0.0 |
| difficulty | intermediate |
| estimated_time | 6-8 hours |
Shell Networking Skill
Master networking operations from the command line
Learning Objectives
After completing this skill, you will be able to:
Prerequisites
- Bash basics
- Basic networking concepts
- Understanding of HTTP
Core Concepts
1. Curl Essentials
curl https://api.example.com
curl -X POST https://api.example.com
curl -o file.zip https://example.com/f
curl -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"key":"value"}' \
https://api.example.com
curl -v url
curl -s url
curl -L url
curl -k url
curl -w "%{http_code}" -o /dev/null -s url
2. SSH Operations
ssh user@host
ssh -p 2222 user@host
ssh -i ~/.ssh/key.pem user@host
scp file.txt user@host:/path/
scp -r dir/ user@host:/path/
scp user@host:/path/file.txt ./
ssh -L 8080:localhost:80 user@host
ssh -D 1080 user@host
3. Port Checking
ss -tlnp
ss -ulnp
netstat -tlnp
nc -zv host 80
lsof -i :8080
nmap -sT host
nmap -p 80,443 host
4. DNS Operations
dig example.com
dig +short example.com
dig example.com MX
dig @8.8.8.8 example.com
host example.com
nslookup example.com
Common Patterns
API Request with Error Handling
response=$(curl -s -w "\n%{http_code}" \
-H "Authorization: Bearer $TOKEN" \
"https://api.example.com/data")
http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | sed '$d')
if [[ "$http_code" != "200" ]]; then
echo "Error: HTTP $http_code"
exit 1
fi
Wait for Port
wait_for_port() {
local host="$1" port="$2" timeout="${3:-30}"
for ((i=0; i<timeout; i++)); do
if nc -z "$host" "$port" 2>/dev/null; then
return 0
fi
sleep 1
done
return 1
}
SSH Config
Host myserver
HostName 192.168.1.100
User admin
Port 2222
IdentityFile ~/.ssh/mykey
Anti-Patterns
| Don't | Do | Why |
|---|
curl | bash | Download, inspect, run | Security risk |
| Store passwords | Use SSH keys | More secure |
| Skip SSL verify | Fix certificates | Security |
Practice Exercises
- API Client: Script to interact with REST API
- Health Checker: Check if services are up
- SSH Automation: Run commands on multiple hosts
- Port Scanner: Simple port availability checker
Troubleshooting
Common Errors
| Error | Cause | Fix |
|---|
Connection refused | Service down | Check if running |
Connection timed out | Firewall/routing | Check network |
Name not resolved | DNS issue | Check DNS |
Permission denied (publickey) | SSH key | Check authorized_keys |
Debug Techniques
ping -c 2 host
traceroute host
curl -v https://example.com
ssh -vvv user@host
Security Guidelines
- Use SSH keys instead of passwords
- Verify SSL certificates in production
- Don't store secrets in scripts
- Use environment variables for credentials
- Audit SSH access regularly
Resources