If you've ever tried to come up with a catchy domain name, you know how annoying it can be to keep checking to see if a certain name is available. Fortunately, on Linux we can make the task a little easier on us by using the whois command. When a domain is available, the output from whois will let us know that it's not able to find any information for that domain.

It's easy enough then to put this functionality into a Bash script, which helps to automate checking lots of different TLDs (Top Level Domains, like .com, .net, .org, etc).

In this guide, we'll show how to check domain name availability from the command line on Linux. Then, we'll give you a simple Bash script that you can copy onto your own system and check for lots of domains at once. Read on to learn how.

In this tutorial you will learn:
  • How to install whois on major Linux distros
  • How to check for domain name availability with whois command
  • Bash script for checking domain name availability
whois script to check many domains and TLDs at once
whois script to check many domains and TLDs at once
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software whois
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Install whois on major Linux distros


SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


In order to check domain availability from the command line, you'll need to have access to the whois command. Use the appropriate command below to install the whois utility with your system's package manager.

To install whois on Ubuntu, Debian, and Linux Mint:

$ sudo apt install whois

To install whois on CentOS, Fedora, AlmaLinux, and Red Hat:

$ sudo dnf install whois

To install whois on Arch Linux and Manjaro:

$ sudo pacman -S whois

Once it's installed, you'll be able to use the example commands below and the Bash script to check for domain availability.

How to check for domain availability

Check to see if a domain is registered to anyone by simply using the whois command and specifying a domain name.

$ whois example.com


Using whois to look up information about a domain name
Using whois to look up information about a domain name

If the domain is taken, you'll see output like that in the screenshot above. It lists when the domain was registered, when it expires, the registrar, and various other registry information.

Contrast that to the output below, where the domain is available and returns a "No match found for" message.

whois tells us that this domain is not taken and can be registered
whois tells us that this domain is not taken and can be registered

It's nice being able to check domain availability from the Linux command line. However, it's not that much more convenient than just checking it in some registrar website. The real convenience can be found by using the Bash script in the section below.

Check domain availability with Bash script

Start by saving the following script to an empty file on your computer.

#!/bin/bash 
 
# Name: Check for domain name availability 
# linuxconfig.org 
# Please copy, share, redistribute and improve 
 
if [ "$#" == "0" ]; then 
    echo "You need tu supply at least one argument!" 
    exit 1
fi 
 
DOMAINS=( '.com' '.co.uk' '.net' '.info' '.mobi' \ 
'.org' '.tel' '.biz' '.tv' '.cc' '.eu' '.ru' \ 
'.in' '.it' '.sk' '.com.au' )
 
ELEMENTS=${#DOMAINS[@]} 
 
while (( "$#" )); do 
 
  for (( i=0;i<$ELEMENTS;i++)); do 
      whois $1${DOMAINS[${i}]} | egrep -q \ 
      '^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' 
	  if [ $? -eq 0 ]; then 
	      echo "$1${DOMAINS[${i}]} : available" 
	  fi 
  done 
 
shift 
 
done

After you save the script, give it execute permissions.

$ chmod +x domaincheck.sh

And then run the script and specify it a domain name you'd like to check for.

$ whois example


whois script to check many domains and TLDs at once
whois script to check many domains and TLDs at once

As you can see in the screenshot above, the output gives us a list of TLDs that are available for our search string. You can also specify more than one query if you want to look up multiple website names.

You can adapt the script as needed, if you want to check for additional TLDs or add more "no match" type of messages to it.

Closing Thoughts

In this guide, we learned how to check for domain name availability from the Linux command line. This is done through the whois tool, but isn't a lot more convenient than using a registrar website to do the same thing. However, with a bit of Bash scripting, we see a sharp increase in efficiency and convenience for this task. Now checking for domain names is easier than ever.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.