1. Overview

In this tutorial, we’ll discuss how to resolve or translate a domain name to an IP address. For this purpose, we’ll be using the following commands: ping, host, nslookup, dig, and nmap.

2. Using the ping Command

The ping utility is used to test for the reachability of a host via an ICMP echo request packet.

It comes preinstalled on many Linux distros, but if it doesn’t come preinstalled on our Linux distro, we can then install it. We can use apt or yum to install iputils-ping on Ubuntu/Debian or iputils-ping on RHEL.

Let’s resolve a domain name to IP address by pinging the domain name:

$ ping baeldung.com
PING baeldung.com (104.26.13.74) 56(84) bytes of data.
64 bytes from 104.26.13.74 (104.26.13.74): icmp_seq=1 ttl=32 time=11.1 ms

When we ping the domain baeldung.com, it replies with the IP address of 104.26.13.74, which is an A record of the domain baeldung.com.

3. Using the host Command

The host command is a DNS lookup utility used to convert domain names to IP addresses and reverse IP lookup.

The command comes preinstalled with many Linux distros, but we can install it if it’s not available on our system. We can use apt or yum to install dnsutils on Ubuntu/Debian or bind-utils on RHEL.

Let’s use the host command and examine the output:

$ host baeldung.com
baeldung.com has address 104.26.12.74
baeldung.com has address 104.26.13.74
baeldung.com has address 172.67.72.45
baeldung.com has IPv6 address 2606:4700:20::ac43:482d
baeldung.com has IPv6 address 2606:4700:20::681a:c4a
baeldung.com has IPv6 address 2606:4700:20::681a:d4a

This will print out all the DNS records like A, AAAA, MX, and other records. But in this case, we might want to check the IPv4 addresses.

Let’s add a type of record to print:

$ host -t a baeldung.com
baeldung.com has address 172.67.72.45
baeldung.com has address 104.26.12.74
baeldung.com has address 104.26.13.74

From the command above, the -t option specifies the type of record to look for. In our case, it’s an A record of the domain name.

4. Using the nslookup Command

Another command we’ll be looking at is the nslookup command which is used to query internet domain names. This command offers similar features to the host command.

By default, the nslookup command comes preinstalled with some Linux distros, but we can install it on our system. The command is part of the DNSUtil or Bind-Utils package that we installed in the host command above. It has two types of mode called interactive mode and non-interactive mode.

Let’s open our terminal and type nslookup with the domain name. This will be a non-interactive mode:

$ nslookup baeldung.com
Name: baeldung.com
Address: 172.67.72.45
Name: baeldung.com
Address: 104.26.12.74
Name: baeldung.com
Address: 104.26.13.74

The non-interactive mode will look up for both IPv4 and IPv6 by default. The interactive mode of nslookup allows us to change the type of DNS record we are looking for, like A, AAA, MX, CNAME, etc.

Using nslookup with the interactive mode is similar:

[email protected]:~$ nslookup
> set type=A
> baeldung.com
Server: 172.31.0.2
Address: 172.31.0.2#53

Non-authoritative answer:
Name: baeldung.com
Address: 104.26.13.74
Name: baeldung.com
Address: 172.67.72.45
Name: baeldung.com
Address: 104.26.12.74

From the command above, From type=A, We can change the DNS record we are looking for, like MX, CNAME, etc.

5. Using the Dig Command

The dig command works similarly with the nslookup command but with more features. The dig command comes preinstalled in some Linux distros, but we can install it if it’s not available on our Linux system.

It is available via the DNSUtil or Bind-Utils package that we saw above.

We can query for any type of DNS record we want with dig. But doing so, we’ll be translating a domain name to an IP. Let’s check for the A record of the domain name:

[email protected]:~$ dig baeldung.com A +short
104.26.13.74
172.67.72.45
104.26.12.74

From the command above, the A record is the IPv4 Address, while the +short means to get a short answer without displaying the Header. Looking for AAAA record of the domain name, which is an IPv6 with dig:

[email protected]:~$ dig baeldung.com AAAA +short
2606:4700:20::681a:c4a
2606:4700:20::681a:d4a
2606:4700:20::ac43:482d

As you can see, we can also check the IPv6 address of the domain name.

6. Using Nmap

Nmap, which stands for Network Mapper, is a tool used for security auditing and scanning large networks.

We can use apt or yum to install nmap on Ubuntu/Debian and RHEL.

Let’s take a look at host discovery with ping scan options:

$ nmap -sn baeldung.com
Starting Nmap 7.80 ( https://nmap.org ) at 2021-08-11 13:51 WAT
Nmap scan report for baeldung.com (104.26.12.74)
Host is up (0.25s latency).
Other addresses for baeldung.com (not scanned): 104.26.13.74 172.67.72.45 2606:4700:20::681a:c4a 2606:4700:20::681a:d4a 2606:4700:20::ac43:482d
Nmap done: 1 IP address (1 host up) scanned in 1.76 seconds

First, the -sn option instructs nmap to a ping scan and disables port scan. We’re using this option since we are only interested in the domain name translation. Finally, the output of nmap above shows the IP addresses of the domain and other IPs associated with the domain.

7. Conclusion

In this tutorial, we learned about different commands that we can use to translate a domain name to IP address. We looked at commands like ping, host, nslookup, dig, and nmap. Finally, we learned how to check for other DNS records with the commands.

1 Comment
Oldest
Newest
Inline Feedbacks
View all comments
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.