How To Look Up DNS on a Linux and Unix Systems

How do I look up for DNS (Domain Name System) information on a Linux or Unix-like systems using command line options?

Linux and Unix-like system uses Internet address (in dot notation) of a name server that the resolver should query to convert host names to IP address and vice versa. The resolver reads a configuration file called /etc/resolv.conf. The name server IP address are stored in /etc/resolv.conf file. Up to three name servers may be listed per line using the following syntax:[donotprint]
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time N/A

nameserver ISP-DNS-IP1
nameserver DNS-IP2
nameserver DNS-IP3

How do I see my DNS server IP address?

Type the following cat command:

cat /etc/resolv.conf

Or use grep command as follows:

grep nameserver /etc/resolv.conf

Sample outputs:

Fig.01: Finding out your DNS lookup IP address on a Linux and Unix

How do I change or update my DNS nameservers IP address?

Use a text editor such as vi, ee, emacs, joe and co to edit the file /etc/resolv.conf as root user:
$ sudo vi /etc/resolv.conf

DNS lookup on a Linux and Unix systems

Now, you know your DNS name server IP address. It is time to use command such as host command and dig command to find out more information about domains or IP address.

dig command examples

Type the following command to resolve domain name called


Sample outputs:

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6_6.1 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9933
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;			IN	A


;; Query time: 47 msec
;; WHEN: Mon Jan 12 11:00:20 2015
;; MSG SIZE  rcvd: 47

To see just IP address, type:

dig +short

Sample outputs:

To see an IPv6 address for, enter:

dig aaaa
dig +short aaaa

Sample outputs:


A few more examples using the dig command:

# list authoritative dns server ##
dig ns
## show mx (mail server) info/ip for domain## 
dig mx
## Reverse lookups — mapping addresses to dns names #
dig -x ip
dig -x

host command examples

The syntax is:

## Get an IPv4 address for ##
## Get mail server info for ##
host -t mx
## Get nameserver info for ##
host -t ns
## Get an IPv6 address ##
host -t aaaa
## Use specific (Google) dns server ip # to query ##
## Get all info about ##
host -a -v

Sample outputs:

Fig.02: Host command outputs in a Linux and Unix-like systems

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum