Bash

DNS Lookup (dig / host / getent)

admin by @admin ADMIN
Jun 16, 2026
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Three options depending on what's installed: dig is most flexible, host is concise, getent uses the system's resolver and respects /etc/hosts.
Bash
Raw
# Resolve a hostname to IP(s)
dig +short example.com                  # 93.184.216.34
host example.com                        # example.com has address 93.184.216.34
getent hosts example.com | awk '{print $1}'   # respects /etc/hosts AND DNS

# Look up MX records
dig +short MX example.com
# 0 .

# Reverse DNS (PTR)
dig +short -x 8.8.8.8                   # dns.google.
host 8.8.8.8

# DNSSEC + TTL info
dig example.com +noall +answer +ttlid

# Query a specific resolver
dig @1.1.1.1 example.com
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.