Command to find IP address of domain name in Linux terminal (five methods)

Time:2020-9-30

This tutorial describes how to verify IP address of domain name or computer name on 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 use these commands effectively to identify IP address information of multiple domains in Linux terminals.

You can do this with the following five commands.

  • Dig command: it is a flexible command line tool for querying DNS name servers.
  • Host command: it is a simple program for performing DNS queries.
  • The NSLOOKUP command: it is used to query the Internet domain name server.
  • Fping command: it is used to send ICMP echo to network host_ Request packet.
  • Ping command: it is used to send ICMP echo to network host_ Request packet.

To test, we created adomains-list.txt And added the following fields.


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

Method 1: how to use dig command to find IP address of domain

The dig command stands for “domain information groper”, which 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 of the query. Most DNS administrators use the dig command to solve DNS problems, because it is flexible, easy to use, and the output is clear.

It also has batch mode to read search requests from a file.


# 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 the IP addresses of 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 contents to the script, give dig- command.sh File sets executable permissions.


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

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 use the host command to find the IP address of a domain

The host command is a simple command-line program that performs 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 see all the 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 the IP addresses of 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 thehost-command.sh File sets executable permissions.


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

Finally, run the bash script to get the output.


# sh /opt/scripts/host-command.sh
2daygeek.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.3

Method 3: how to use the NSLOOKUP command to find the IP address of a domain

The NSLOOKUP command is a program used to query the Internet domain name server (DNS).

NSLOOKUP has two modes, interactive and non interactive. Interactive mode allows users to query name servers for information about various hosts and domains, or to print a list of hosts in the 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.


# 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

Use the following bash script to find the IP addresses of 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 " " - - -

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


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

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

Method 4: how to use fping command to find IP address of domain

The fping command is a program like ping, which uses Internet control message protocol (ICMP) echo request to determine whether the target host responds.

Fping is different from Ping in that it allows users to Ping any number of hosts in parallel. In addition, it can be imported from a text file to the host.

Fping sends ICMP echo request and moves to the next target in a circular manner without waiting for the target host to respond.

If the target host replies, mark it as an active host and remove it from the list of targets to check; if the target does not respond within a specific time limit and / or retrying limit, it is designated as 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

Method 5: how to use ping command to find IP address of domain

The ping command is a network program used to test the availability / connectivity of hosts on Internet Protocol (IP) networks.

The availability of the host is verified by sending ICMP echo request packets to the target host and waiting for ICMP echo response.

It summarizes statistical results based on sent packets, received packets, lost packets, and usually contains minimum / average / maximum time.


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

Use the following bash script to find the IP addresses of 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 " " - -

After adding the above content to the script, give theping-command.shFile sets executable permissions.


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

Finally, run the bash script to get the output.


# sh /opt/scripts/ping-command.sh
2daygeek.com - 104.27.156.177
magesh.co.in - 104.18.35.52
linuxtechnews.com - 104.27.144.3

summary

The above are the five commands for searching IP address of domain name in Linux terminal introduced by Xiaobian. I hope it will be helpful for you. If you have any questions, please leave me a message, and I will reply you in time. Thank you very much for your support to the developeppaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

Recommended Today

Redis (1)

Redis About redis Remote dictionary server (redis) is a key value storage system. Redis is an open source log type, key value database written in ANSI C language, complying with BSD protocol, supporting network, memory based and persistent, and providing API in multiple languages. It is often referred to as a data structure server, because […]