| name | dns-network |
| description | Network debugging with DNS lookups, connectivity testing, and latency diagnosis. Use when user mentions "dns", "dig", "nslookup", "traceroute", "ping", "network debugging", "why is this slow", "connection timeout", "dns resolution", "curl timing", "network latency", "MTR", "netcat", or diagnosing network issues. |
DNS & Network Debugging
Practical workflows for diagnosing DNS, connectivity, and latency problems.
DNS Lookups
dig (preferred tool)
dig example.com
dig example.com AAAA
dig example.com MX
dig example.com CNAME
dig example.com TXT
dig example.com NS
dig example.com SOA
dig +short example.com
dig +short example.com MX
dig @8.8.8.8 example.com
dig @1.1.1.1 example.com
dig +trace example.com
dig -x 93.184.216.34
dig example.com ANY +noall +answer
dig -f domains.txt +short
nslookup
nslookup example.com
nslookup example.com 8.8.8.8
nslookup -type=MX example.com
nslookup -type=TXT example.com
host (quick and simple)
host example.com
host -t MX example.com
host 93.184.216.34
Checking DNS Propagation
When you change DNS records, check multiple resolvers to see if the change has spread:
for dns in 8.8.8.8 1.1.1.1 208.67.222.222 9.9.9.9; do
echo "--- $dns ---"
dig @$dns example.com +short
done
Check the authoritative nameserver directly to confirm the record is correct at the source:
dig +short example.com NS
dig @ns1.example.com example.com +short
Connectivity Testing
ping
ping example.com
ping -c 5 example.com
ping -c 5 -i 0.2 example.com
ping -W 2 example.com
ping -t 2 example.com
What to look for: packet loss percentage and round-trip time variation. Consistent high latency is different from intermittent packet loss -- they point to different problems.
traceroute / tracepath
traceroute example.com
traceroute -n example.com
traceroute -T -p 443 example.com
traceroute -I example.com
Read the output hop by hop. A sudden jump in latency at a specific hop identifies where the slowdown is. Stars (* * *) mean that hop is filtering probes -- not necessarily a problem.
mtr (combines ping + traceroute)
mtr example.com
mtr -r -c 100 example.com
mtr -rw -c 50 example.com
mtr -T -P 443 example.com
mtr is the best single tool for diagnosing path-level problems. The Loss% and Avg columns per hop tell you exactly where packets are being dropped or delayed.
curl Timing Breakdown
This is the go-to for diagnosing "the site is slow" complaints:
curl -o /dev/null -s -w "\
DNS lookup: %{time_namelookup}s\n\
TCP connect: %{time_connect}s\n\
TLS handshake: %{time_appconnect}s\n\
First byte: %{time_starttransfer}s\n\
Total time: %{time_total}s\n\
HTTP code: %{http_code}\n" \
https://example.com
How to read the output:
- time_namelookup high (>100ms): DNS is slow. Check resolver, try 8.8.8.8.
- time_connect - time_namelookup high: Network path to server is slow.
- time_appconnect - time_connect high: TLS negotiation is slow (cert chain issues, slow server).
- time_starttransfer - time_appconnect high: Server is slow to generate the response (backend problem).
- time_total - time_starttransfer high: Large response body or slow transfer rate.
curl verbose mode for HTTP debugging
curl -v https://example.com
curl --trace - https://example.com
curl -I https://example.com
curl -vL https://example.com 2>&1 | grep -E '< HTTP|< Location'
Port Testing
netcat (nc)
nc -zv example.com 443
nc -zv example.com 80
nc -zv example.com 20-25
nc -zv -w 3 example.com 443
nc -zuv example.com 53
Checking listening ports on local machine
ss -tlnp
ss -ulnp
ss -tlnp | grep :8080
ss -s
netstat -tlnp
netstat -an | grep LISTEN
lsof -i :8080
lsof -i -P -n | grep LISTEN
tcpdump Basics
sudo tcpdump -i eth0
sudo tcpdump -i eth0 host example.com
sudo tcpdump -i eth0 port 443
sudo tcpdump -i eth0 port 53
sudo tcpdump -i eth0 tcp
sudo tcpdump -i eth0 udp and port 53
sudo tcpdump -i eth0 -w capture.pcap port 443
sudo tcpdump -r capture.pcap
sudo tcpdump -A -i eth0 port 80
sudo tcpdump -c 100 -i eth0 port 443
sudo tcpdump -i any -n port 53
On macOS, use en0 (Wi-Fi) or en1 instead of eth0. Run tcpdump -D to list available interfaces.
Local Configuration Files
/etc/hosts
Static hostname-to-IP mappings. Checked before DNS.
cat /etc/hosts
echo "93.184.216.34 example.com" | sudo tee -a /etc/hosts
sudo sed -i '/example.com/d' /etc/hosts
sudo sed -i '' '/example.com/d' /etc/hosts
/etc/resolv.conf
DNS resolver configuration.
cat /etc/resolv.conf
On systems using systemd-resolved, the actual config may be managed elsewhere. Check with resolvectl status.
On macOS, DNS is managed by the system. Check with scutil --dns.
Diagnostic Workflows
"The site is slow"
- Run the curl timing breakdown to isolate which phase is slow.
- If DNS is slow: check
dig +short time, try alternate resolvers.
- If connect is slow: run
mtr -r -c 50 to find where latency spikes.
- If TLS is slow: check
curl -v for cert chain issues or protocol negotiation problems.
- If first-byte is slow: the problem is server-side. Check application logs and server resources.
- If transfer is slow: check response size, consider compression, test bandwidth.
"I can't connect to the service"
- Can you resolve the hostname?
dig +short hostname
- Can you reach the IP?
ping -c 3 <ip>
- Is the port open?
nc -zv hostname port
- Is something listening locally?
ss -tlnp | grep :port
- Is a firewall blocking?
sudo iptables -L -n (Linux) or check security groups if cloud-hosted.
- Is the route correct?
traceroute -n hostname
"DNS isn't resolving"
- Check what resolver you are using:
cat /etc/resolv.conf or scutil --dns (macOS).
- Query the resolver directly:
dig @<resolver-ip> hostname
- Query a known-good public resolver:
dig @8.8.8.8 hostname
- If public works but local does not: local resolver or network is the problem.
- If neither works: check if the domain actually has records:
dig +trace hostname
- Check for /etc/hosts overrides that might be interfering.
"Works from my machine but not from the server"
- Compare DNS results from both machines:
dig +short hostname
- Compare routes:
mtr -r -c 20 hostname from both.
- Check if the server has outbound firewall rules or proxy settings.
- Check if the server uses a different resolver (corporate DNS, VPN split-tunnel).
- Check environment variables:
env | grep -i proxy
Quick Reference
| Task | Command |
|---|
| Resolve hostname | dig +short example.com |
| Reverse lookup | dig -x 1.2.3.4 |
| Check MX records | dig +short example.com MX |
| Trace DNS path | dig +trace example.com |
| Test port open | nc -zv host 443 |
| Find what is on a port | lsof -i :8080 |
| Listening ports | ss -tlnp |
| Path analysis | mtr -r -c 50 host |
| Capture DNS traffic | sudo tcpdump -i any -n port 53 |
| Full curl timing | curl -o /dev/null -s -w "dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} firstbyte:%{time_starttransfer} total:%{time_total}\n" URL |