Which of the following Linux commands will resolve a domain name into IP address?

Improve Article

Save Article

host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more specific details of a domain by specifying the corresponding option along with the domain name.

Syntax:

host [-aCdlriTWV] [-c class] [-N ndots] [-t type] [-W time]
     [-R number] [-m flag] hostname [server]

host command without any option: It will print the general syntax of the command along with the various options that can be used with the host command as well as gives a brief description about each option.

Example:

Which of the following Linux commands will resolve a domain name into IP address?

Different options with the host command:

  • host domain_name: This will print the IP address details of the specified domain.

    Example:

    host geeksforgeeks.org

    Which of the following Linux commands will resolve a domain name into IP address?

  • host IP_Address: This will display the domain details of the specified IP Address.

    Example:

    host 52.25.109.230

    Which of the following Linux commands will resolve a domain name into IP address?

  • -a or -v: It used to specify the query type or enables the verbose output.

    Example:

    host -a geeksforgeeks.org 

    Which of the following Linux commands will resolve a domain name into IP address?

  • -t : It is used to specify the type of query.

    Example 1:

    host -t ns geeksforgeeks.org  

    Which of the following Linux commands will resolve a domain name into IP address?

    Example 2: To print SOA record

    host -t SOA geeksforgeeks.org  

    Which of the following Linux commands will resolve a domain name into IP address?

    Example 3: To print txt record

    host -t txt geeksforgeeks.org  

    Which of the following Linux commands will resolve a domain name into IP address?

  • -C : In order to compare the SOA records on authoritative nameservers.

    Example:

    host -C geeksforgeeks.org 

    Which of the following Linux commands will resolve a domain name into IP address?

  • -R : In order to specify the number of retries you can do in case one try fails. If anyone try succeeds then the command stops.

    Example:

    host -R 3 geeksforgeeks.org 

    Which of the following Linux commands will resolve a domain name into IP address?

  • -l :In order to list all hosts in a domain.For this command to work you need to be either an admin or a node server.

    Example:

    host -l geeksforgeeks.org 

The solutions given so far mostly work in the simpler case: the hostname directly resolves to a single IPv4 address. This might be the only case where you need to resolve hostnames, but if not, below is a discussion on some cases that you might need to handle.

Chris Down and Heinzi briefly discussed the case where the hostname resolves to more than one IP addresses. In this case (and others below), basic scripting under the assumption that a hostname directly resolves to a single IP address may break. Below, an example with a hostname resolving to more than a single IP address:

$ host www.l.google.com
www.l.google.com has address 209.85.148.147
www.l.google.com has address 209.85.148.103
www.l.google.com has address 209.85.148.99
www.l.google.com has address 209.85.148.106
www.l.google.com has address 209.85.148.105
www.l.google.com has address 209.85.148.104

But what is www.l.google.com? This is where the alias case needs to be introduced. Let's check the example below:

$ host www.google.com
www.google.com is an alias for www.l.google.com.
www.l.google.com has address 74.125.39.103
www.l.google.com has address 74.125.39.147
www.l.google.com has address 74.125.39.105
www.l.google.com has address 74.125.39.99
www.l.google.com has address 74.125.39.106
www.l.google.com has address 74.125.39.104

So www.google.com does not directly resolve to IP addresses, but to an alias that itself resolves to multiple IP addresses. For more information on aliases, check here. Of course, the case where an alias has a single IP address is possible, as shown below:

$ host g.www.ms.akadns.net
g.www.ms.akadns.net is an alias for lb1.www.ms.akadns.net.
lb1.www.ms.akadns.net has address 207.46.19.190

But can aliases be chained? The answer is yes:

$ host www.microsoft.com
www.microsoft.com is an alias for toggle.www.ms.akadns.net.
toggle.www.ms.akadns.net is an alias for g.www.ms.akadns.net.
g.www.ms.akadns.net is an alias for lb1.www.ms.akadns.net.
lb1.www.ms.akadns.net has address 207.46.19.254

$ host www.google.fr
www.google.fr is an alias for www.google.com.
www.google.com is an alias for www.l.google.com.
www.l.google.com has address 74.125.39.147
www.l.google.com has address 74.125.39.103
www.l.google.com has address 74.125.39.99
www.l.google.com has address 74.125.39.106
www.l.google.com has address 74.125.39.104
www.l.google.com has address 74.125.39.105

I did not find any example where a hostname resolves to an alias that does not resolve to an IP address, but I think the case might occur.

More than multiple IP addresses and aliases, is there some other special cases... what about IPv6? You could try:

$ host ipv6.google.com
ipv6.google.com is an alias for ipv6.l.google.com.
ipv6.l.google.com has IPv6 address 2a00:1450:8007::68

Where the hostname ipv6.google.com is an IPv6-only hostname. What about dual-stack hostnames:

$ host www.facebook.com
www.facebook.com has address 66.220.153.15
www.facebook.com has IPv6 address 2620:0:1c08:4000:face:b00c::

Again about IPv6, if your host is IPv4 only, you can still resolve IPv6 addresses (tested on a IPv4 only WinXP and with ipv6.google.com, you could try it on Linux). In this case, the resolution succeeds, but a ping fails with an unknown host error message. This might be a case where your scripting fails.

I hope those remarks were useful.

What resolves domain names to IP addresses?

DNS servers convert URLs and domain names into IP addresses that computers can understand and use. They translate what a user types into a browser into something the machine can use to find a webpage. This process of translation and lookup is called DNS resolution.

Which of the following commands can be used to resolve a DNS name to an IP address?

The Nslookup command is available on many of the popular computer operating systems like Windows, macOS, and Linux distros. You can use it to perform DNS queries and receive: domain names or IP addresses, or any other specific DNS Records.