Sagar.BlogArticle
All posts
All posts
Linux

ping, traceroute, dig — Network Diagnostics

Test connectivity with ping, trace network routes with traceroute, and perform DNS lookups with dig and nslookup.

March 10, 20255 min read
linuxnetworkingpingdigtraceroute

ping — Test Connectivity

ping sends ICMP echo requests to a host and reports if it responds. Essential for basic network debugging.

ping google.com                # Continuous (Ctrl+C to stop)
ping -c 5 google.com           # Send exactly 5 packets
ping -i 2 google.com           # 2 second interval
ping 192.168.1.1               # Ping by IP
ping localhost                 # Ping yourself (127.0.0.1)

traceroute — Trace the Path

traceroute shows every router (hop) packets pass through to reach their destination.

traceroute google.com          # Full trace
traceroute -n google.com       # Skip DNS (faster, numeric IPs)
traceroute -m 15 google.com    # Limit to 15 hops
# macOS: traceroute
# Linux alt: tracepath (no root needed)

dig — DNS Lookup

dig is the most powerful DNS query tool — shows full DNS record details.

dig google.com                 # Full query
dig google.com +short          # IP only
dig google.com A               # IPv4 record
dig google.com AAAA            # IPv6 record
dig google.com MX              # Mail servers
dig google.com NS              # Name servers
dig @8.8.8.8 google.com        # Query specific DNS (Google's)
dig -x 142.250.80.46           # Reverse: IP → domain

nslookup & host

nslookup google.com            # Basic lookup
nslookup google.com 8.8.8.8   # Specific DNS server

host google.com                # Quick lookup
host 142.250.80.46             # Reverse lookup

Use ping -c 3 google.com for a quick connectivity check — the -c 3 stops after 3 packets so you don't have to press Ctrl+C.

Quick Check

Which command shows every router hop between you and a destination?

Exercise

Use dig google.com +short to get just Google's IP. Then use dig -x <ip> with that IP for a reverse lookup.