Commands to find domain IP address in Linux terminal (five methods)

Commands to find domain IP address in Linux terminal (five methods)

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

This can be done 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 used to perform DNS queries.
  • nslookup command: It is used to query the Internet domain name server.
  • fping command: It is used to send ICMP ECHO_REQUEST packets to network hosts.
  • ping command: It is used to send ICMP ECHO_REQUEST packets to network hosts.

For testing, we created a file called domains-list.txt and added the following domains.

# 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 dig command

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 queried name servers. Most DNS administrators use the dig command to troubleshoot DNS problems because of its flexibility, ease of use, and clear output.

It also has a batch mode and can 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 content 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 above script in one 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 the IP addresses of 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 host command

The host command is a simple command-line program for performing DNS queries. It is commonly used to convert names to IP addresses and vice versa. If no arguments or options are given, host prints a summary of its command line arguments 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 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, set executable permissions for the host-command.sh file.

# 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 find the IP address of a domain using the nslookup command

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 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 the requested information.

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

# 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, set executable permissions for the nslookup-command.sh file.

# 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 find the IP address of a domain using fping command

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

fping differs from ping in that it allows the user to ping any number of hosts in parallel. Alternatively, it can import hosts from a text file.

fping sends ICMP echo requests and moves to the next target in a round-robin fashion without waiting for the target host to respond.

If the target host replies, it is marked as active and removed from the list of targets to be checked; if the target does not respond within a certain time limit and/or retry limit, it is designated as unreachable.

# 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 find the IP address of a domain using the ping command

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

Verifies the availability of a host by sending Internet Control Message Protocol (ICMP) Echo Request packets to the target host and waiting for the ICMP Echo Reply.

It summarizes statistics based on packets sent, packets received, packets lost, and usually includes min/avg/max times.

# 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, set executable permissions for the ping-command.sh file.

# 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

Summarize

The above are the 5 commands I introduced to you for finding the domain name IP address in the Linux terminal. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed explanation of how to use socks5 proxy for Linux terminal
  • Android's implementation method of executing shell scripts in the Linux terminal to directly print the log of the currently running app
  • How to use Shell script to get terminal width in Linux
  • Get a list of your top 10 most frequently used terminal commands in Linux
  • Two tools for splitting the screen in the Linux command line terminal
  • Two methods of terminal split screen under Linux (screen and tmux)
  • Detailed explanation of commonly used shortcut keys for Linux terminal command line
  • How to exit the Python command line in the Linux terminal
  • Linux uses stty to display and modify terminal line settings

<<:  JS operation object array to achieve add, delete, modify and query example code

>>:  mysql installer community 8.0.16.0 installation and configuration graphic tutorial

Recommend

Use xshell to connect to the Linux server

Benefits of using xshell to connect to Linux We c...

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

Serial and parallel operations in JavaScript

Table of contents 1. Introduction 2. es5 method 3...

Analysis and treatment of scroll bars in both HTML and embedded Flash

We often encounter this situation when doing devel...

Summary of 6 solutions for implementing singleton mode in JS

Preface Today, I was reviewing the creational pat...

Implementing parameter jump function in Vue project

Page Description:​ Main page: name —> shisheng...

XHTML three document type declarations

XHTML defines three document type declarations. T...

MySQL uses inet_aton and inet_ntoa to process IP address data

This article will introduce how to save IP addres...

The complete code of the uniapp packaged applet radar chart component

Effect picture: The implementation code is as fol...

Basic usage of @Font-face and how to make it compatible with all browsers

@Font-face basic introduction: @font-face is a CSS...

How to use an image button as a reset form button

When we make a form, we often set a submit button ...

JavaScript String Object Methods

Table of contents Methods of String Object Method...

Detailed explanation of Nginx access restriction configuration

What is Nginx access restriction configuration Ng...