This tutorial shows how to verify IP addresses for domain names or computer names on Linux terminals. This tutorial will allow you to examine multiple fields at once. You may have already used these commands to validate information. However, we will teach you how to effectively use these commands to identify IP address information for multiple domains on Linux terminals.

You can use the following five commands to do this.

  • digCommand: it is a flexible command line tool for querying DNS name servers.
  • hostCommand: this is a simple program for performing DNS queries.
  • nslookupCommand: This is used to query the Internet domain name server.
  • fpingCommand: it is used to send ICMP ECHO_REQUEST packets to network hosts.
  • pingCommand: it is used to send ICMP ECHO_REQUEST packets to network hosts.

To test, we created a file called domains-list.txt and added the following fields.

# vi /opt/scripts/domains-list.txt

2daygeek.com
magesh.co.in
linuxtechnews.com
Copy the code

Method 1: How do I use the dig command to find the DOMAIN IP address

The dig command stands for Domain Information Groper and is a powerful and flexible command line tool for querying DNS name servers.

It performs a DNS query and displays the return information from the name server being queried. Most DNS administrators use the DIG command to solve DNS problems because of its flexibility, ease of use, and clarity of output.

It also has batch mode, which reads search requests from files.

# dig 2daygeek.com | awk '{print $1,$5}'2 daygeek.com. 104.27.157.177 2 daygeek.com 104.27.156.177Copy the code

Use the following bash script to find IP addresses for multiple domains.

# vi /opt/scripts/dig-command.sh

#! /bin/bash
for server in `cat /opt/scripts/domains-list.txt`
do echo $server "-"
dig $server +short
done | paste -d "" - - -
Copy the code

After adding the above to the script, set executable permissions to the dig-command-sh file.

# chmod +x /opt/scripts/dig-command.sh
Copy the code

Finally, run the bash script to get the output.

# sh /opt/scripts/dig-command.sh

2daygeek.com - 104.27.156.177 104.27.157.177
magesh.co.in - 104.18.35.52 104.18.34.52
linuxtechnews.com - 104.27.144.3 104.27.145.3
Copy the code

If you want to run the above script on a single line, use the following script.

# for server in 2daygeek.com magesh.co.in linuxtechnews.com; do echo $server "-"; dig $server +short; done | paste -d " " - - -
Copy the code

Alternatively, you can use the following Shell script to find IP addresses for multiple domains.

# for server in 2daygeek.com magesh.co.in linuxtechnews.com; do dig $server | awk '{print $1,$5}'; done2daygeek.com. 104.27.157.177 2daygeek.com. 104.27.156.177 Magesh.co.in. 104.18.34.52 Magesh.co.in. 104.18.35.52 Linuxtechnews.com 104.27.144.3 linuxtechnews.com 104.27.145.3Copy the code

Method 2: How do I use the host command to find the IP address of a domain

The host command is a simple command-line program used to perform DNS queries. It is commonly used to convert names to IP addresses and vice versa. If no arguments or options are provided, host prints a summary of its command-line arguments and options.

You can view all the record types in a domain by adding specific options or record types to the host command.

# host 2daygeek.com | grep "has address" | sed 's/has address/-/g'

2daygeek.com - 104.27.157.177
2daygeek.com - 104.27.156.177
Copy the code

Use the following bash script to find IP addresses for multiple domains.

# vi /opt/scripts/host-command.sh

for server in `cat /opt/scripts/domains-list.txt`
do host $server | grep "has address" | sed 's/has address/-/g'
done
Copy the code

After adding the above content to the script, set the executable permission to the host-command-sh file.

# chmod +x /opt/scripts/host-command.sh
Copy the code

Finally, run the bash script to get the output.

# sh /opt/scripts/host-command.sh2daygeek.com - 104.27.156.177 2daygeek.com - 104.27.157.177 Magesh.co.in-104.18.35.52 Magesh.co.in-104.18.34.52 Linuxtechnews.com - 104.27.144.3 LinuxTechnews.com - 104.27.145.3Copy the code

Method 3: How do I use the nslookup command to search for the DOMAIN IP address

The nslookup command is used to query the Internet domain name server (DNS) 5.

Nslookup has two modes, interactive and non-interactive. The interactive mode allows the user to query the name server for information about various hosts and domains, or to print a list of hosts in a domain. Non-interactive mode is used to print only the name of the host or domain and requested information.

It is a network management tool that helps diagnose and resolve DNS related problems.

# nslookup -q=A 2daygeek.com | tail -n+4 | sed -e '/^$/d' -e 's/Address://g' | grep -v 'Name|answer' | xargs -n1

104.27.157.177
104.27.156.177
Copy the code

Use the following bash script to find IP addresses for multiple domains.

# vi /opt/scripts/nslookup-command.sh

#! /bin/bash
for server in `cat /opt/scripts/domains-list.txt`
do echo $server "-"
nslookup -q=A $server | tail -n+4 | sed -e '/^$/d' -e 's/Address://g' | grep -v 'Name|answer' | xargs -n1 done | paste -d "" - - -
Copy the code

After adding the preceding content to the script, set the executable permission for the nslookup-command.

# chmod +x /opt/scripts/nslookup-command.sh
Copy the code

Finally, run the bash script to get the output.

# sh /opt/scripts/nslookup-command.sh

2daygeek.com - 104.27.156.177 104.27.157.177
magesh.co.in - 104.18.35.52 104.18.34.52
linuxtechnews.com - 104.27.144.3 104.27.145.3
Copy the code

Method 4: How do I use the fping command to query the IP address of a domain

The fping command is a program like ping that uses Internet Control Message Protocol (ICMP) echo requests to determine whether the target host is responding.

Fping is different from ping because it allows users to ping any number of hosts in parallel. In addition, it can input hosts from text files.

Fping sends an ICMP Echo request and moves to the next destination in a loop, without waiting for the destination host to respond.

If the target host replies, it is marked as active and removed from the list of targets to check; If the target does not respond within a specific time limit and/or retry limit, it is designated inaccessible.

# fping -A -d 2daygeek.com magesh.co.in linuxtechnews.com

104.27.157.177 (104.27.157.177) is alive
104.18.35.52 (104.18.35.52) is alive
104.27.144.3 (104.27.144.3) is alive
Copy the code

Method 5: How do I use the ping command to query the IP address of a domain

The ping command (Packet Internet Groper) is a network program used to test the availability/connectivity of hosts on an Internet protocol (IP) network.

Verify the availability of the host by sending the Internet Control Message Protocol (ICMP) Echo request packet to the target host and waiting for the ICMP Echo reply.

It summarizes statistics based on packets sent, received, and lost, usually including min/average/Max time.

# ping -c 2 2daygeek.com | head -2 | tail -1 | awk '{print $5}' | sed 's/[(:)]//g'

104.27.157.177
Copy the code

Use the following bash script to find IP addresses for multiple domains.

# vi /opt/scripts/ping-command.sh

#! /bin/bash
for server in `cat /opt/scripts/domains-list.txt`
do echo $server "-"
ping -c 2 $server | head -2 | tail -1 | awk '{print $5}' | sed 's/[(:)]//g'
done | paste -d "" - -
Copy the code

After adding the above content to the script, set the executable permission for the ping-command-sh file.

# chmod +x /opt/scripts/ping-command.sh
Copy the code

Finally, run the bash script to get the output.

# sh /opt/scripts/ping-command.sh2daygeek.com - 104.27.156.177 Magesh.co.in-104.18.35.52 LinuxTechnews.com - 104.27.144.3Copy the code

Via: www.2daygeek.com/linux-comma…

Magesh Maruthamuthu (lujun9972

This article is originally compiled by LCTT and released in Linux China