Solved

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

Posted on 2004-08-06
6
914 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
  • 4
6 Comments
 
LVL 20

Expert Comment

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

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 20

Expert Comment

by:tfewster
ID: 11737624
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 20

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 42
Java core in Solaris 10 1 281
Invalid password trying to cannect to Unix server 2 78
Image not there 4 53
Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
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.

785 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