In this postt, we will cover various methods you can use to resolve a given IP address to its hostname using reverse DNS lookup.
When you are just getting started in networking, you will come across instances where you need to determien the hostname from a given IP address. This can help you fetch additional information such as mail servers, etc.
Method 1 - Using the Host Command
One of the most popular and easy method you can use to resolve a given IP to it's hostname is the host
command. The host
command is a simple and powerful command-line utility that allows you to perofrm a reverse DNS lookup.
We can use it convert an IP address to the target hostname and vice versa.
To check the hostname of a given address, we can run the command:
hostname 1.1.1.1
Thec ommand should perform a reverse DNS lookup and return the target hostname as shown:
$ sudo host 1.1.1.1
Password:
1.1.1.1.in-addr.arpa domain name pointer one.one.one.one.
Method 2 - Using nslookup command
nslookup is a command-line utility used to query Internet domain name servers. Nslookup has two modes: interactive and non-interactive. Interactive mode allows the user to query name servers for information about various hosts and domains or to print a list of hosts in a domain. Non-interactive mode is used to print just the name and requested information for a host or domain.
We can use the nslookup
command to resolve a given IP address to the target hostname as shown:
nslookup 1.1.1.1
The command should show information about the target about IP, including the hostname. An example is as shown:
(base) csalem@macbook ~ % nslookup 1.1.1.1
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
1.1.1.1.in-addr.arpa name = one.one.one.one.
Authoritative answers can be found from:
Method 3 - Using dig Command
One of the most influential utilities in network troubleshooting and diagnostics is dig
. Dig or Domain Information Gropper allows you to perform DNS lookups with quick and well-formated response from the terminal. dig provides a comprehensive suite of utilities for troubleshooting.
For us case, we can use to check the hostname of a given IP using the command as shown:
dig -x 1.1.1.1
The -x
option allows you to perform a reverse lookup and map an IP address to a given hostname.
An example output is as shown:
; <<>> DiG 9.10.6 <<>> -x 1.1.1.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63936
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;1.1.1.1.in-addr.arpa. IN PTR
;; ANSWER SECTION:
1.1.1.1.in-addr.arpa. 247 IN PTR one.one.one.one.
;; Query time: 2 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Thu Sep 29 22:58:34 EAT 2022
;; MSG SIZE rcvd: 78
By default, dig
will provide extra information about the specified host. To only the hostname, run the command:
dig -x 1.1.1.1 +noall +answer
Resulting output:
;; global options: +cmd
1.1.1.1.in-addr.arpa. 179 IN PTR one.one.one.one.
Using the +noall
option supresses all the lines from the output. To include the hostname in the output, we can use the +answer
which displays the ;;ANSWER SECTION
.
Closing
Through this post, you discovered three main methods of resolving a given IP address to its target hostname.
We hope you enjoyed this post, if you did, leave us a comment down below and share with your friends.
Check out our other topics to expand your knowledge.
Thanks for reading, catch you in the next one.