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][/donotprint]

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

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts