Networking
Networking — Quick Reference
Section titled “Networking — Quick Reference”curl — HTTP Requests
Section titled “curl — HTTP Requests”# GET requestcurl https://api.example.com/users
# Pretty-print JSON responsecurl https://api.example.com/users | jq .
# POST with JSON bodycurl -X POST https://api.example.com/users \ -H "Content-Type: application/json" \ -d '{"name": "vivek"}'
# With auth headercurl -H "Authorization: Bearer TOKEN" https://api.example.com
# Follow redirectscurl -L https://example.com
# Save response to filecurl -o output.json https://api.example.com/data
# Show response headerscurl -I https://example.com
# Verbose (show request + response headers)curl -v https://example.com
# Upload a filecurl -F "file=@report.pdf" https://upload.example.com
# Send form datacurl -X POST -d "user=vivek&pass=secret" https://example.com/login
# Set timeoutcurl --max-time 10 https://example.comwget — Download Files
Section titled “wget — Download Files”wget https://example.com/file.zip # download filewget -O output.zip https://example.com/file.zip # custom filenamewget -r https://example.com # recursive downloadwget -c https://example.com/file.zip # resume incomplete downloadwget -q https://example.com/file.zip # quiet modessh — Remote Login
Section titled “ssh — Remote Login”ssh user@host # connectssh -p 2222 user@host # custom portssh -i ~/.ssh/key.pem user@host # specific key
# Run a single command remotelyssh user@host "ls -la /var/log"
# Port forwarding — local:8080 → remote:80ssh -L 8080:localhost:80 user@host
# Reverse tunnel — remote:9090 → local:3000ssh -R 9090:localhost:3000 user@host
# Keep connection alivessh -o ServerAliveInterval=60 user@hostSSH Config (~/.ssh/config)
Section titled “SSH Config (~/.ssh/config)”Host myserver HostName 192.168.1.100 User vivek IdentityFile ~/.ssh/id_rsa Port 22Then just: ssh myserver
scp — Copy Files Over SSH
Section titled “scp — Copy Files Over SSH”# Local → Remotescp file.txt user@host:/remote/path/
# Remote → Localscp user@host:/remote/file.txt ./local/
# Copy directoryscp -r ./dir user@host:/remote/path/
# Custom portscp -P 2222 file.txt user@host:/path/rsync — Sync Files Over Network
Section titled “rsync — Sync Files Over Network”Better than scp for large transfers — skips unchanged files.
# Sync local dir to remotersync -avz ./src/ user@host:/remote/src/
# Sync remote to localrsync -avz user@host:/remote/src/ ./src/
# Dry run (preview what would change)rsync -avzn ./src/ user@host:/remote/src/
# Delete files on dest that don't exist in sourcersync -avz --delete ./src/ user@host:/remote/src/
# Exclude a directoryrsync -avz --exclude=node_modules ./src/ user@host:/remote/| Flag | Meaning |
|---|---|
-a | Archive (preserves permissions, timestamps, symlinks) |
-v | Verbose |
-z | Compress during transfer |
-n | Dry run |
--delete | Remove extra files on destination |
netstat / ss — Open Ports & Connections
Section titled “netstat / ss — Open Ports & Connections”ss is the modern replacement for netstat.
ss -tuln # all listening TCP/UDP portsss -tulnp # include process namess -s # summary statsnetstat -tuln # same with netstatnetstat -an | grep :8080 # check specific portping / traceroute — Diagnose Connectivity
Section titled “ping / traceroute — Diagnose Connectivity”ping google.com # check connectivityping -c 4 google.com # send only 4 packets
traceroute google.com # show hops to destinationtracepath google.com # alternative (no root needed)mtr google.com # live traceroute (combines ping + traceroute)lsof -i — What’s Using a Port
Section titled “lsof -i — What’s Using a Port”lsof -i :8080 # process on port 8080lsof -i TCP:3000 # TCP on port 3000lsof -i -n -P # all network connections, no DNS lookupnmap — Port Scanning
Section titled “nmap — Port Scanning”nmap localhost # scan common ports on localhostnmap -p 80,443,8080 host # scan specific portsnmap -p 1-65535 host # scan all portsnmap -sV host # detect service versionsdig / nslookup — DNS Lookup
Section titled “dig / nslookup — DNS Lookup”dig example.com # DNS lookupdig example.com A # A record onlydig example.com MX # mail recordsdig @8.8.8.8 example.com # query specific DNS server
nslookup example.com # simpler alternative- Use
curl -vwhen debugging API issues — it shows the full request and response headers. rsync --dry-runbefore any real sync to avoid accidental overwrites.ssh -Llocal port forwarding is essential for accessing remote services (databases, dashboards) securely.ss -tulnpis your first stop when a port isn’t responding as expected.