Linux whois Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux whois command to retrieve information about domain names, IP addresses, and other internet resources. The lab covers the purpose and syntax of the whois command, how to customize the output, and how to handle exceptions. You will start by understanding the basic usage of the whois command, then move on to retrieving detailed domain information, and finally explore ways to customize the command's output. This lab is designed to provide you with practical knowledge and skills in the networking and communication domain.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/TextProcessingGroup(["`Text Processing`"]) linux/BasicSystemCommandsGroup -.-> linux/test("`Condition Testing`") linux/PackagesandSoftwaresGroup -.-> linux/curl("`URL Data Transferring`") linux/TextProcessingGroup -.-> linux/grep("`Pattern Searching`") subgraph Lab Skills linux/test -.-> lab-423010{{"`Linux whois Command with Practical Examples`"}} linux/curl -.-> lab-423010{{"`Linux whois Command with Practical Examples`"}} linux/grep -.-> lab-423010{{"`Linux whois Command with Practical Examples`"}} end

Understand the Purpose and Syntax of the whois Command

In this step, you will learn about the purpose and syntax of the whois command in Linux. The whois command is a tool used to retrieve information about domain names, IP addresses, and other internet resources.

To use the whois command, open a terminal and type the following command:

whois example.com

This will display the available information about the example.com domain, including the registrant, registration date, expiration date, and other details.

The basic syntax of the whois command is:

whois [options] [query]

Here, [options] are the optional flags you can use to customize the output, and [query] is the domain name, IP address, or other resource you want to look up.

Some common options for the whois command include:

  • -h or --host: Specifies the WHOIS server to use for the lookup.
  • -p or --port: Specifies the port number to use for the WHOIS lookup.
  • -r or --raw: Displays the raw WHOIS response without any formatting.
  • -6: Performs the WHOIS lookup using IPv6.

Example output:

Domain Name: EXAMPLE.COM
Registry Domain ID: 2336799_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.example.com
Registrar URL: http://www.example.com
Updated Date: 2023-04-01T12:00:00Z
Creation Date: 1995-08-14T04:00:00Z
Registry Expiry Date: 2024-08-14T04:00:00Z
Registrant Organization: Example Corporation
Registrant State/Province: California
Registrant Country: US

This output shows the key information about the example.com domain, including the registrant, creation date, and expiration date.

Retrieve Domain Information Using the whois Command

In this step, you will learn how to use the whois command to retrieve detailed information about a domain.

First, let's look up the information for the example.com domain:

whois example.com

This will display the full WHOIS record for the example.com domain, including the registrant, registration date, expiration date, and other details.

Example output:

Domain Name: EXAMPLE.COM
Registry Domain ID: 2336799_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.example.com
Registrar URL: http://www.example.com
Updated Date: 2023-04-01T12:00:00Z
Creation Date: 1995-08-14T04:00:00Z
Registry Expiry Date: 2024-08-14T04:00:00Z
Registrant Organization: Example Corporation
Registrant State/Province: California
Registrant Country: US

Now, let's try looking up the information for a different domain, such as google.com:

whois google.com

Example output:

Domain Name: GOOGLE.COM
Registry Domain ID: 2138514_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.registrar.com
Registrar URL: http://www.registrar.com
Updated Date: 2023-03-15T08:00:00Z
Creation Date: 1997-09-15T04:00:00Z
Registry Expiry Date: 2024-09-14T04:00:00Z
Registrant Organization: Google LLC
Registrant State/Province: California
Registrant Country: US

As you can see, the whois command provides detailed information about the domain, including the registrant, registration date, and expiration date.

Customize whois Output and Handle Exceptions

In this step, you will learn how to customize the output of the whois command and handle exceptions that may occur.

First, let's try customizing the output of the whois command. You can use the -h or --host option to specify the WHOIS server to use for the lookup. For example, to use the WHOIS server for the .com top-level domain, you can run:

whois -h whois.verisign-grs.com example.com

This will display the WHOIS information for the example.com domain using the Verisign WHOIS server.

You can also use the -r or --raw option to display the raw WHOIS response without any formatting:

whois -r example.com

Example output:

   Domain Name: EXAMPLE.COM
   Registry Domain ID: 2336799_DOMAIN_COM-VRSN
   Registrar WHOIS Server: whois.example.com
   Registrar URL: http://www.example.com
   Updated Date: 2023-04-01T12:00:00Z
   Creation Date: 1995-08-14T04:00:00Z
   Registry Expiry Date: 2024-08-14T04:00:00Z
   Registrant Organization: Example Corporation
   Registrant State/Province: California
   Registrant Country: US

Now, let's try handling exceptions that may occur when using the whois command. If a domain does not exist or the WHOIS server is unavailable, the whois command will return an error message. For example, let's try looking up a non-existent domain:

whois non-existent-domain.com

Example output:

No match for "non-existent-domain.com".

To handle these exceptions, you can use a combination of the whois command and shell scripting. For example, you can check the exit code of the whois command to determine if the lookup was successful:

whois example.com
if [ $? -eq 0 ]; then
  echo "WHOIS lookup successful"
else
  echo "WHOIS lookup failed"
fi

By using these techniques, you can customize the whois command output and handle exceptions that may occur during the lookup process.

Summary

In this lab, you learned about the purpose and syntax of the whois command in Linux, which is used to retrieve information about domain names, IP addresses, and other internet resources. You explored the basic command structure, including optional flags to customize the output, and saw examples of the information that can be retrieved, such as the registrant, registration date, and expiration date. You also learned how to use the whois command to look up detailed information about a specific domain, and how to handle exceptions when the command returns incomplete or unavailable data.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like