Solved

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

Posted on 2004-08-06
6
910 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now