Is there a way to use DNS lookup for many hosts at once?

currentuser

New Member
Joined
Feb 8, 2020
Messages
3
Reaction score
1
Credits
0
For example you can do 'host IP' and that'll give you the hostname, etc., but for many hosts at once... is there an easy way to have the host command point at a text file, search and spit out the hostnames for each address? If someone can give me some tips or point me in the right direction, i'd appreciate it.
 


Maybe I'm missing something here, but this is exactly what the /etc/hosts file does.
If you don't have a "real" local DNS server. Simply add lines similar to the following to
the bottom of this file. The down side is... you need static IP's on these systems.

batman batman.mycomics.com 10.10.1.3
superman superman.mycomics.com 10.10.1.4
flash flash.mycomics.com 10.10.1.5
grnlatern grnlatern.mycomics.com 10.10.1.6

If you don't a fully qualified domain name, just leave off the 3rd column, it isn't required.

spiderman 10.10.1.7

works also.

It's possible on some systems you may have to edit the /etc/nsswitch.conf file.

the lines that says "hosts" should look like this.

hosts: files, dns

This forces the system to look at the /etc/hosts file before it tries to do a DNS query.
Just make sure the "files" is before the "dns".
 
Last edited:
Maybe I'm missing something here, but this is exactly what the /etc/hosts file does.

Oh, i was thinking something along the lines of a shell script. Never did it the way you proposed, do you think that'd be quicker over a script?
 
Much quicker and easier.
 
Hm - i'm thinking he's looking to look up a number of hosts right?

If you're looking to go through a file of hostnames or ips all at once and spit out their IPs, you can do something like this..

Create a file, one fqdn per line like:
Code:
blah.linux.org
blah2.linux.org
blah3.linux.org
We'll call that file 'fqdn.txt'

Then, query each of them with:
for i in $(cat fqdn.txt);do echo "$i";dig $i +short;done

If you're looking to reverse lookup ips to fqdns, do the same thing, but put IPs in that file, and run:
for i in $(cat fqdn.txt);do echo "$i";dig -x $i +short;done
 
If you're looking to reverse lookup ips to fqdns, do the same thing, but put IPs in that file, and run:
for i in $(cat fqdn.txt);do echo "$i";dig -x $i +short;done


Bingo. This is exactly what I needed. Well done. Thank you!
 
  • Like
Reactions: Rob

Members online


Top