Network and DNS in Linux: ping and dig
Updated July 3, 2026
ping checks whether packets reach a host, and dig looks up an IP address from a domain name.
Common cases
ping example.com # do packets get through, and how fast
ping -c 4 example.com # exactly 4 packets, then stop
dig example.com # the IP for a name
dig +short example.com # just the address, nothing else
dig MX example.com # the domain's mail servers
cat /etc/resolv.conf # which DNS server is usedHow it works: name, address and reachability
These are two different questions.
diganswers 'what address does this name have': it asks a DNS server (its address is in/etc/resolv.conf) and returns an IP.pinganswers 'do packets reach this address': it sends short ICMP packets and waits for a reply. So ifpingby name fails, checkdigfirst. Maybe the name does not resolve, and the link is fine. For debugging you can hard-code names in/etc/hosts, bypassing DNS.
In the book
This topic is covered in full in the chapter Networking basics.