DNS translates human-readable domain names into IP addresses that computers use to communicate. Whether you’re troubleshooting connectivity, verifying DNS propagation, or simply curious about a website’s infrastructure, Linux provides powerful command-line tools for DNS resolution.
[!TIP] Real-World Scenario: Your application suddenly can’t reach
api.example.com. Is it a DNS issue or is the server down? A quickdigcommand reveals whether the domain resolves and which IP addresses are returned, narrowing your troubleshooting scope immediately.
How do I use dig to find a website’s IP address?
dig (Domain Information Groper) is the most comprehensive DNS lookup tool, providing detailed query and response information that network administrators rely on.
Basic DNS lookup
dig example.com
Sample output:
; <<>> DiG 9.18.18 <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 86400 IN A 93.184.216.34
;; Query time: 52 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sun Apr 26 09:30:45 UTC 2026
The ANSWER SECTION contains the A record with the IPv4 address (93.184.216.34).
Dig query options
# Short answer only (just the IP)
dig +short example.com
# Query specific DNS server
dig @8.8.8.8 example.com
# Get IPv6 address (AAAA record)
dig example.com AAAA
# Get all record types
dig example.com ANY
# Trace the full resolution path
dig +trace example.com
# Reverse DNS lookup (IP to domain)
dig -x 93.184.216.34
Understanding dig output sections
| Section | Purpose |
|---|---|
QUESTION SECTION | Shows what was queried |
ANSWER SECTION | Contains the DNS records |
AUTHORITY SECTION | Lists authoritative name servers |
ADDITIONAL SECTION | Extra records (e.g., name server IPs) |
Query time | How long the lookup took |
How do I use host for simple IP lookups?
host provides cleaner output than dig when you just need the IP address without extra detail.
Basic host lookup
host example.com
Output:
example.com has address 93.184.216.34
example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946
example.com mail is handled by 0 .
Host command options
# IPv4 only
host -4 example.com
# IPv6 only
host -6 example.com
# Specific record type
host -t MX example.com # Mail servers
host -t NS example.com # Name servers
host -t TXT example.com # Text records (SPF, DKIM)
# Use specific DNS server
host example.com 1.1.1.1
How do I use nslookup for DNS queries?
nslookup offers interactive and non-interactive modes for DNS investigation.
Non-interactive usage
nslookup example.com
Output:
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: example.com
Address: 93.184.216.34
Interactive mode
nslookup
> server 8.8.8.8 # Switch to Google's DNS
> set type=MX # Query mail records
> example.com # Query domain
> exit # Quit
Query specific record types
# Mail exchanger records
nslookup -query=MX example.com
# Name servers
nslookup -query=NS example.com
# Start of Authority (SOA)
nslookup -query=SOA example.com
Syntax for host command
host <websiteURL>
How do I verify connectivity after finding the IP?
After resolving a domain, verify the host is reachable:
# Ping test (4 packets)
ping -c 4 example.com
# Or ping the IP directly
ping -c 4 93.184.216.34
# Check routing path
traceroute example.com
# Port connectivity test (HTTP)
curl -I http://example.com
Summary
| Command | Best For | Output Style |
|---|---|---|
dig | Detailed troubleshooting | Verbose, complete DNS data |
host | Quick IP lookup | Clean, human-readable |
nslookup | Interactive exploration | Flexible record queries |
ping | Connectivity + resolution | Simple reachability test |
- Use
dig +shortfor scripting (parsable output) - Use
hostfor quick manual lookups - Use
nslookupwhen exploring different record types - All tools are pre-installed on Ubuntu 26.04 Desktop and Server
FAQ
Why does dig show different IPs than host?
Both tools query the same DNS system but may use different default name servers or caching. Specify the same server with @server (dig) or trailing argument (host) for consistent results.
Can I find a website’s IP if DNS is down?
No. DNS resolution requires functioning name servers. If DNS fails, you need alternative methods like checking /etc/hosts, browser cache, or cached records from previous lookups.
What is the difference between A and AAAA records?
- A records contain IPv4 addresses (e.g.,
93.184.216.34) - AAAA records contain IPv6 addresses (e.g.,
2606:2800:220:1:248:1893:25c8:1946) Modern dual-stack systems support both.
How do I find my own public IP address?
# Query external service
curl -s ifconfig.me
# Or:
dig +short myip.opendns.com @resolver1.opendns.com
Why does the same domain return multiple IPs? Load balancing and CDN distribution. Multiple A records distribute traffic across servers. Each query may return a different IP from the pool.
What to Read Next
- Control Auto-Suspend on Ubuntu 26.04 — manage network connections during power state changes
- Install and Configure Git on Ubuntu 26.04 — version control for your networking scripts
- Delete Local Git Branch Using Terminal — clean up after experimenting with network automation scripts
Related Articles
Deepen your understanding with these curated continuations.
Create directories or folders in Linux with mkdir command
The `mkdir` command comes handy to make one or more directories aka folders in Linux system. This article shows the basic usage of mkdir command with examples.
Linux command: dirname
The `dirname` command comes handy to retrieve path where the file is saved. This article shows the usage of dirname command with example.
20+ Things to Do After Installing Ubuntu 26.04 Resolute Raccoon
The ultimate post-installation checklist for Ubuntu 26.04 Resolute Raccoon. From Kernel 7.0 optimizations and UI polish to setting up a high-speed developer toolchain in 2026.