Solved

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

Posted on 2004-08-06
6
922 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

688 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