Solved

How to use nslookup if the machine does not access to any DNS server?

Posted on 2004-08-06
6
919 Views
Last Modified: 2013-12-27
Hi,

We've a DB server (Oracle) running on a Sun Solaris. This server has no access to any DNS server. The only thinng it has for host names lookup is the file /etc/hosts. Inside the file /etc/nsswitch.conf, there is the line "hosts: dns files" So, a service to lookup

My first question: Is it possible to make nslookup look into the file /etc/hosts for the host name lookup, instead of using a DNS server?

If it is not possible, can I think that the line "host: dns files" inside nsswitch.conf has no effect on nslookup?

If you know some way to make nslookup to use /etc/hosts for host name resolution, please give some help. Any help is appreciated.

Thanks,

Rfr1tz
0
Comment
Question by:rfr1tz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 21

Expert Comment

by:tfewster
ID: 11737350
Change the line to read
hosts: files
0
 
LVL 21

Expert Comment

by:tfewster
ID: 11737518
Oops, `nslookup` on Solaris only works for DNS, and  so will always fail; But "normal" functions like gethostbyname will obey the rules in nsswitch.conf
0
 
LVL 21

Expert Comment

by:tfewster
ID: 11737624
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:jgiordano
ID: 11737816
With nslookup there is an option to nslookup on a specific name server and bypass the resolv.conf.

the syntax is:

nslookup  <host>  [ nameserver ]

Hope this helps
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 11739124
Thanks for all the info.
We cannot set this up as a DNS server due to security concern. There is a suggestion that writing a script named "nslookup" that actually reads the lines of /etc/hosts and do the job exactly the same as nslookup (of course, we've to rename the real nslookup).

However, I've no idea about how to start wrting this script. If you have some ideas about how to create this kind of script, please help.

Thanks a lot,

Rfr1tz

0
 
LVL 21

Accepted Solution

by:
tfewster earned 250 total points
ID: 11739772
How accurately do you want it to mimic nslookup? Just to return the IP address, or the full output?

$ nslookup www.experts-exchange.com
*** Can't find server name for address 10.0.0.2: Non-existent domain
*** Default servers are not available
Server:  UnKnown
Address:  10.0.0.2

Non-authoritative answer:
Name:    experts-exchange.com
Address:  64.156.132.140
Aliases:  www.experts-exchange.com


No doubt there is a better way, but this script should work for any legally-formed hosts file, e.g.
# Next line is myhost
127.0.0.1      myhost myhost. # comment
127.0.0.2      myhost             # Duplicate name - Bad!
127.0.0.3      myhost2


nslookup.ksh:

#!/usr/bin/ksh
usage="Usage: nslookup.ksh hostname"

if  [ $* -ne 1 ]
then
   echo $usage
   exit 1
fi

host=$1

grep $host /etc/hosts|grep -v "^#" |sed -e 's/^I/  /g' -e 's/$/ /' |grep " $host " |head -1 |awk '{print $1}'
# 1) grep all matching lines from hosts file
# 2) Eliminate "comment" lines
# 3) Replace tabs with spaces & put a space at the end of the line
# 4) grep again, but this time for exactly " hostname " (a space either side )
# 5) In case of duplicate entries, only return the first
# 6) print the first field (the IP address)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unistall fileset without dependecies on AIX 3 71
LastLogonTimeStamp Attribute 7 49
UNIX SCP 5 87
Unix Script: Loop over all days of a month 17 116
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question