Networking — Practical
Networking — Practical (commands & tricks)
Section titled “Networking — Practical (commands & tricks)”Diagnostics
Section titled “Diagnostics”# DNSdig +short example.com Adig +trace example.com # full resolution pathnslookup -type=MX example.comhost -a example.com
# Connectivityping -c 4 example.comtraceroute example.com # or tracepath / mtrmtr --report --report-cycles=10 example.com
# Sockets / connectionsss -tnp # TCP listening + connected with PIDsss -s # summarynetstat -anp | grep :8080lsof -i :8080 # what's on port
# Process file descriptorsls /proc/<pid>/fd | wc -lcat /proc/<pid>/limits
# Kernel TCP statscat /proc/net/sockstatsysctl net.ipv4.tcp_max_syn_backlogHTTP debugging
Section titled “HTTP debugging”# headers + verbosecurl -vI https://example.com
# follow redirects, save bodycurl -L -o /tmp/x.html https://example.com
# show timingcurl -w '@-' -o /dev/null -s https://example.com <<'EOF'time_namelookup: %{time_namelookup}\ntime_connect: %{time_connect}\ntime_appconnect: %{time_appconnect}\ntime_pretransfer: %{time_pretransfer}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\nEOF
# specific HTTP versioncurl --http2 -v ...curl --http3 -v ...
# custom headers, bodycurl -X POST -H 'content-type: application/json' -d '{"x":1}' https://api/x# inspect certopenssl s_client -showcerts -connect example.com:443 -servername example.com </dev/null
# expiryecho | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \ | openssl x509 -noout -dates
# verify chainopenssl verify -CAfile /etc/ssl/certs/ca-certificates.crt cert.pem
# generate CSRopenssl req -new -newkey rsa:4096 -keyout key.pem -out csr.pem -nodes \ -subj "/CN=example.com"
# self-signed for devopenssl req -x509 -newkey rsa:2048 -days 365 -nodes -keyout k.pem -out c.pem -subj "/CN=localhost"Packet capture
Section titled “Packet capture”sudo tcpdump -nn -i any -s 0 -w out.pcap port 8080sudo tcpdump -nn 'tcp port 80 and host 1.2.3.4'
# readtcpdump -r out.pcap -nn -Awireshark out.pcap # GUICommon kernel tunings (Linux, server)
Section titled “Common kernel tunings (Linux, server)”net.core.somaxconn = 65535net.ipv4.tcp_max_syn_backlog = 65535net.core.netdev_max_backlog = 50000net.ipv4.ip_local_port_range = 1024 65535net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_fin_timeout = 15net.ipv4.tcp_keepalive_time = 60net.ipv4.tcp_keepalive_intvl = 10net.ipv4.tcp_keepalive_probes = 6net.ipv4.tcp_congestion_control = bbrfs.file-max = 2097152# applysudo sysctl --system
# raise per-process FDsulimit -n 1048576Nginx as L7 reverse proxy (sketch)
Section titled “Nginx as L7 reverse proxy (sketch)”upstream app { least_conn; keepalive 64; server 10.0.0.10:8080 max_fails=3 fail_timeout=30s; server 10.0.0.11:8080 max_fails=3 fail_timeout=30s;}
server { listen 443 ssl http2; ssl_certificate /etc/ssl/cert.pem; ssl_certificate_key /etc/ssl/key.pem; ssl_protocols TLSv1.2 TLSv1.3;
location / { proxy_pass http://app; proxy_http_version 1.1; proxy_set_header Connection ""; # required for upstream keepalive proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 30s; proxy_connect_timeout 5s; }}HAProxy basic L4
Section titled “HAProxy basic L4”frontend tcp_in bind *:6379 mode tcp default_backend redis_pool
backend redis_pool mode tcp balance leastconn option tcp-check server r1 10.0.0.20:6379 check server r2 10.0.0.21:6379 check backupProbing HTTP/2 / 3
Section titled “Probing HTTP/2 / 3”curl -o /dev/null -s -w '%{http_version}\n' https://example.com # 2 or 3nghttp -nv https://example.comLoad testing
Section titled “Load testing”# autocannonnpx autocannon -d 30 -c 100 https://api/endpoint
# wrkwrk -t8 -c200 -d30s --latency https://api/endpoint
# k6 (scripted scenarios)k6 run --vus 200 --duration 1m script.jsLatency measurement gotchas
Section titled “Latency measurement gotchas”- Always report percentiles (p50/p95/p99/p999), not averages.
- Coordinated omission: many tools wait for response before sending next; under saturation, this masks tail latency. Use tools that fix this (
wrk2,k6). - Warm-up phase before measuring.
SSL termination strategies
Section titled “SSL termination strategies”| Approach | Pros | Cons |
|---|---|---|
| At LB only | simpler app, central cert | LB ↔ app plaintext (private network) |
| End-to-end (re-encrypt) | encrypted internally | overhead, cert mgmt everywhere |
| mTLS via service mesh | strong identity, zero trust | mesh complexity |
Recommended reading
Section titled “Recommended reading”- High Performance Browser Networking — Ilya Grigorik (free online).
- Cloudflare’s blog (TCP, TLS, QUIC posts).
- AWS Networking & Content Delivery blog.
- “It’s always DNS” — Julia Evans guides.