Find domain in linux

How to get a hostname/domain name from an IP address in Linux

One of the questions that many Linux users ask is how they can retrieve a system’s hostname using its IP address. It may seem an uphill task, but in the real sense, it’s quite easy. Essentially, this is known as the reverse DNS lookup. Reverse DNS lookup queries an IP address to retrieve the hostname or domain of the server. The exact opposite is the Forward DNS lookup which maps the domain name to the IP address.

In this short guide, we have explored a few ways to performs Reverse DNS lookup and get a domain name from an IP address. For demonstration purposes, I have used Ubuntu 20.04.

Prerequisites

Before you roll up your sleeves, ensure that your remote host has an A record which is a DNS entry that points or maps a domain name to an IP address

Perform DNS Reverse lookup using dig command

Dig command is a flexible and powerful tool that is used for querying or probing DNS records. It’s an acronym for domain information groper and allows you to retrieve a wide array of DNS information such as A, CNAME, MX, and SOA records.

Perform DNS Reverse lookup using nslookup command

A nslookup command is a troubleshooting tool that features highly in a sysadmin’s armory. It’s a versatile tool that performs all DNS record querying such as CNAME, A, MX, and reverses or PTR records.

To retrieve a domain name from an IP address, use the command syntax:

Perform DNS Reverse lookup using the host command

Similarly, you can use the host command to obtain a hostname or domain name from an IP address using the syntax as shown.

For example, to check the domain name for the IP 5.9.235.235, execute the command:

Читайте также:  Cbl mariner linux iso

Just like the Nslookup command, you can also use the host command with hostnames or IP addresses.

Conclusion

The few examples that we have just elaborated are a sure way of helping you obtain the domain name from an IP address. Usually, the reverse DNS lookup is trivial and not as crucial as the forward lookup, which maps domain names to IP addresses. Your feedback or contribution will be highly welcomed.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

Источник

Useful ‘host’ Command Examples for Querying DNS Lookups

Host command is a minimal and easy-to-use CLI utility for performing DNS lookups which translate domain names to IP addresses and vice versa. It can also be used to list and verify various types of DNS records such as NS and MX, test and validate ISP DNS server and Internet connectivity, spam and blacklisting records, detecting and troubleshooting DNS server issues among others.

In this article, we will learn how to use host command with a few useful examples in Linux to perform DNS lookups. In previous articles, we showed the most used 8 Nslookup commands for testing and troubleshooting DNS servers and to query specific DNS resource records (RR) as well.

We also explained 10 Linux Dig (Domain Information Groper) commands to query DNS info, it works more like the Nslookup tool. The host utility also works in a similar way and comes preinstalled on most if not all mainstream Linux distros.

With that said, let’s look at these 14 host commands below.

Find the Domain IP Address

This is the simplest host command you can run, just provide a domain name such as google.com to get the associated IP addresses.

$ host google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com.

Find Domain Name Servers

To find out the domain name servers use the -t option.

$ host -t ns google.com google.com name server ns1.google.com. google.com name server ns2.google.com. google.com name server ns3.google.com. google.com name server ns4.google.com.

Find Domain CNAME Record

To find out the domain CNAME, run.

$ host -t cname mail.google.com mail.google.com is an alias for googlemail.l.google.com.

Find Domain MX Record

To find out the MX records for a domain.

$ host -n -t mx google.com ogle.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com.

Find Domain TXT Record

To find out the TXT records for a domain.

$ host -t txt google.com google.com descriptive text "v=spf1 include:_spf.google.com ~all"

Find Domain SOA Record

You can make host attempt to display the SOA records for specified zone, from all the listed authoritative name servers for that zone with the -C flag.

$ host -C google.com Nameserver 216.239.38.10: google.com has SOA record ns1.google.com. dns-admin.google.com. 156142728 900 900 1800 60 Nameserver 216.239.32.10: google.com has SOA record ns3.google.com. dns-admin.google.com. 156142728 900 900 1800 60 Nameserver 216.239.34.10: google.com has SOA record ns4.google.com. dns-admin.google.com. 156142728 900 900 1800 60 Nameserver 216.239.36.10: google.com has SOA record ns2.google.com. dns-admin.google.com. 156142728 900 900 1800 60

Query Particular Name Server

To query particual domain name server.

$ host google.com ns4.google.com Using domain server: Name: ns4.google.com Address: 216.239.38.10#53 Aliases: google.com has address 172.217.19.46 google.com has address 172.217.19.46 google.com has address 172.217.19.46 google.com has IPv6 address 2a00:1450:4005:808::200e google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com.

Find All Information of Domain Records and Zones

To make a query of type ANY, use the -a (all) option which is equivalent to setting the -v option.

$ host -a google.com Trying "google.com" ;; ->>HEADER

Get Domain TTL Information

To find out domain TTL information.

$ host -v -t a google.com Trying "google.com" ;; ->>HEADER

Use Either IPv4 or IPv6

The -4 or -6 option forces host to use only IPv4 or only IPV6 query transport respectively.

$ host -4 google.com OR $ host -6 google.com

Perform Non-Recursive Queries

The -r option performs non-recursive queries, note that setting this option clears the RD (recursion desired), the bit in the query which host makes.

$ host -rR 5 google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com.

Set UDP Retries for a Lookup

By default the number of UDP tries is 1, to change it, use the -R flag.

$ host -R 5 google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com.

Set Query Time Wait for Reply

Using the -W switch, you can instruct host to wait for a reply for the specified time in seconds and if the -w flag is used, it makes host to wait forever for a reply:

$ host -T -W 10 google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com.

That’s it! In this article, we learned how to use host command with a few useful examples in Linux. Use the feedback form below to share any thoughts with us concerning this guide.

Источник

How to find the domain name of a server?

I'm having trouble finding the domain name of my school's server, I read another question similar to this but their commands didn't work. I tried to use nslookup and then when I was prompted I entered server . I get the following output. I don't understand where the domain name is stored. I'm using a wired LAN connection from my university.

Default Server: 127.0.01 Address: 127.0.0.1#53 Default Server: ::1 Address: ::1#53 

please would you clarify [. ] and then when I was prompted I entered server , you do know the server ip right? thx

3 Answers 3

You should nslookup the IP. It will return. Example.

[nazu@healer ~]$ nslookup > bro-ns-01 Server: 10.100.1.2 Address: 10.100.1.2#53 Name: bro-ns-01.angelsofclockwork.net Address: 10.100.1.2 > 10.100.1.2 Server: 10.100.1.2 Address: 10.100.1.2#53 2.1.100.10.in-addr.arpa name = bro-ns-01.angelsofclockwork.net. > 

I'm assuming you're using dnsmasq or otherwise, because your server address is set to your localhost. If that's the case, it should still be transparent enough to pull the information.

You could also look at /etc/resolve.conf if you're on the same network. You're more than likely being given a reverse DNS entry that has the same domain suffix of static servers.

[nazu@healer ~]$ cat /etc/resolv.conf ; generated by /usr/sbin/dhclient-script search angelsofclockwork.net. nameserver 10.100.1.2 

Источник

Оцените статью
Adblock
detector