Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I have a list of 2 /24s worth of IP addresses in seperate text files. What I am interested in doing is finding a way to resolve the hosts of these IP addresses and filter out to display only the top level domain.

for example; resolves to

using shell scripting would it then be possible to filter out and append the result to a new file displaying resolves to

the reason for this is internally in the given /24s I am working with I have virtual machines such as web1-10 and mail-10 and i'd like to filter these matches to know only the domains I am running on my netblocks.

Thank you very much Team, I appreciate any assistance to help find a solution with this.

Best, Nick

share|improve this question
up vote 1 down vote accepted
for IP in $(cat file1.txt file2.txt); do
  echo "$IP resolves to $(dig +short -x $IP)"
share|improve this answer

once you have resolved the names, pipe your output to this :

awk -F'.' -v OFS='.' '{print $(NF-1),$NF}'

credit :

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.