Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-06
6
Medium Priority
?
925 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 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.

618 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