Link to home
Start Free TrialLog in
Avatar of richsark
richsarkFlag for United States of America

asked on

Use dig to read input file and pipe to individual files

Hi all,
I have a zonelist.txt file

In the file the contents are standard forward and reverse zones.  For example

db.test.com
db.sark.hello.com
db.177.6.206.in-addr.arpa

I would like a bash or a shell script that uses dig to transfer each of the contents into individual files based on the zone and put them into a folder called transfer.

For example if I do a list in that folder I would have individual flies. For example

db.test.com
db.sark.hello.com
db.177.6.206.in-addr.arpa

I use a Mac and I thought I could use
dig @100.100.100.100 -f zonelist.txt

But that just shows them on screen and not in individual files.

Lastly. Is any zone transfer is refused or failes and or for any reason it does not get that zone to make a file called errors.txt
Avatar of noci
noci

Dig is a DNS query & debugging tool   does a query and send the resopnse to stdout
-f  just reads a text file and does a query for each line read where the first element on a line us a name to be queried.

From the question i am not sure what you want.....  
a) Get a Full dig output per name and each in a file?
b) Just get the answer section... of all names.  which would be all A records... as that is the defailt.
c) Or do you want zone transfers...
d) Or ????????

a)
cat zonelist.txt | while read name rem
do
   dig @100.100.100.100 $name >dig-out-$name
done

Open in new window


b)
dig @100.100.100.100 -f zonelist.txt +noall +answer  >dig-answer-output.txt

Open in new window


c)
cat zonelist.txt | while read zone rem
do
   dig @100.100.100.100 afxr $zone >dig-zone-$zone
done

Open in new window


d)
?????????



Then about the zone file...
If you have a file called db.test.com
The the very contents of the file could very well be the test.com contents
You can verify by reading the file (more probably a text file)  and look for lines containing $ORIGIN..., those lines establish the default for following lines w.r.t. zones
if No origiin lines are found then all element names MUST be FQDNs.

SOA records are the ones that define if it is start of a zone (all names below it belong there, unless there is a sub SOA record).
Also Zones are pointed to by NS records. (so called glue records), which tell the responsible NS for that zone.
Avatar of richsark

ASKER

Hello. Yes I want to do a full zone transfer based on the zone names  fwd and reverse on my list into separate dB.files  if any are refused or fail to log them in an error list file.
you can only get those through axfr. And that needs allowed access.
Otherwise you need to know all names (and types) and do the "right" queries.

the A query on a CNAME will provide the A record....
Reverse lookups need to be done by IP address ... then again how could you publish your own tables for reverse lookup?
You need at least the delegation for part of the table to your site.
Hi. I have the primary name server set to allow transfer to any for all zones
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Keep in mind... "Yes I want to do a full zone transfer based on the zone names  fwd and reverse on my list into separate dB.files"

All major DNS servers have disabled AXFR by default for years, to enhance security.

You'll likely only be able do dig AXFR data on servers you personally setup + then enable AXFR.

If you're doing this for your own servers to produce some data to work with + can enable AXFR on all servers, likely your project will work.

If you're attempting to dig on other zones you have no control over, likely all you'll have is a very large errors file.