Command for finding domain name IP address in Linux terminal of five methods

  • 2021-07-10 21:20:40
  • OfStack

This tutorial shows you how to validate the IP address of a domain name or computer name on an Linux terminal. This tutorial will allow you to check multiple domains at once. You may have used these commands to verify information. However, we will teach you how to effectively use these commands to identify IP address information for multiple domains in an Linux terminal.

You can do this using the following 5 commands.

dig Command: It is a flexible command-line tool for querying DNS name servers. host Command: It is a simple program for executing DNS queries. nslookup command: It is used to query the Internet domain name server. fping command: This is used to send ICMP ECHO_REQUEST packets to network hosts. ping command: This is used to send ICMP ECHO_REQUEST packets to network hosts.

For testing, we created a file named domains-list.txt And added the following fields.


# vi /opt/scripts/domains-list.txt
2daygeek.com
magesh.co.in
linuxtechnews.com

Method 1: How to find the IP address of a domain using the dig command

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

It executes the DNS query and displays the return information from the name server of the query. Most DNS administrators use the dig command to solve DNS problems because of its flexibility, ease of use, and clear output.

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


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

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 " " - - -

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


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

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

If you want to run the above script in line 1, use the following script.


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

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}'; done
2daygeek.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.3

Method 2: How to find the IP address of a domain using the host command

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

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


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

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

After adding the above content to the script, give host-command.sh File sets executable permissions.


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

Finally, run the bash script to get the output.


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

Method 3: How to find the IP address of a domain using the nslookup command

The nslookup command is a program for querying the Internet Domain Name Server (DNS).

nslookup has two modes, interactive and non-interactive. Interactive mode allows users 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 the requested information.

It is a network management tool that can help diagnose and solve DNS-related problems.


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

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


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

After adding the above content to the script, give nslookup-command.sh File sets executable permissions.


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

Finally, run the bash script to get the output.


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

Method 4: How to find the IP address of a domain using the fping command

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

fping differs from ping in that it allows users to parallel any number of ping hosts. In addition, it can enter the host from a text file.

The fping sends the ICMP echo request and loops to the next target without waiting for the target host to respond.

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


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

Method 5: How to find the IP address of a domain using the ping command

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

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

It aggregates statistics based on packets sent, packets received, packets lost, and usually minimum/average/maximum times.


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

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


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

After adding the above content to the script, give ping-command.sh File sets executable permissions.


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

Finally, run the bash script to get the output.


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

Summarize


Related articles: