?
Solved

My Solaris System lookup DNS first instead of files

Posted on 2010-03-30
25
Medium Priority
?
745 Views
Last Modified: 2013-12-27
Dear all,
   I'm facing a strange problem : my solaris server use DNS to resolve a host first before using files.
   I check the nsswitch.conf and see that the setting is correct :

hosts :    files     dns
ipnodes:   files   dns

  My hosts file : /etc/hosts
 192.168.1.1        abcserver

  But when I ping :   ping -s  abcserver
                  64 bytes replied from abcserver.com.vn  (72.xxx.xxx.xxx)
                  64 bytes replied from abcserver.com.vn  (72.xxx.xxx.xxx)
     With  72.xxx.xxx.xxx is an internet IP
 
  When I use command : getent hosts abcserver
     The result is OK :   abcserver   192.168.1.1

  So, I don't know what the problem was ? Please help me to fix It.
  Best regards.

 
0
Comment
Question by:sacombank-sbs
  • 10
  • 7
  • 4
  • +2
25 Comments
 
LVL 9

Expert Comment

by:Amol
ID: 29099665
clear your hosts cache and then try,

nscd –i hosts
0
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 29100566
Is it possible that you are not using the bundled system ping program? Try running
"which ping".

0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29125367
First of all checking /etc/hosts should be linked to /etc/inet/hosts with the same contain.
Secondly which version of Solaris it is.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29154049
Also verify the local host by

# ping -s localhosts

and check the /etc/hosts file should have this entry:

127.0.0.1       localhost loghost loopback
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29154636
The reason asking version of Solaris was as follow:

"hosts:" in /etc/nsswitch.conf  is used only if the /etc/netconfig file has a "-" for nametoaddr_libs of "inet" transports in early version of Solaris.
0
 

Author Comment

by:sacombank-sbs
ID: 29162454
I fixed the problem by :
cat /etc/hosts >> /etc/inet/ipnodes

I wonder why my system just check ipnodes file  instead of hosts file.
0
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 29202037
You never said what version of Solaris you are using, but if it is a newer version of Solaris 10 or Open Solaris, then there is supposed to only be one file, /etc/inet/hosts. The other two files (/etc/inet/ipnodes, /etc/hosts) are both supposed to be
symbolic links to the /etc/inet/hosts file.
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29249663
cat /etc/hosts >> /etc/inet/ipnodes

You shoudln't do that. Instead put this entry "127.0.0.1       localhost loghost loopback" in the hosts file.

The entries of /etc/inet/ipnodes file only contains few information than the hosts file, samething like:

#
# Internet host table
#
::1             localhost
127.0.0.1       localhost

One of them is the localhost entry!
0
 

Author Comment

by:sacombank-sbs
ID: 29284300
We are using Solaris 10 . Actually, I was faced with this issue with Solaris 8    3 years ago.
As Ganios said that the ipnodes files should contain few information that the hosts file, I don't think make a symbolic link to hosts file is a good idea (It's not default for Solaris, is it ?)
But I still don't know why my Solaris system use ipnodes instead of hosts ? May be some cases this issue happens ?
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29284443
Check if both files are hard linked ?
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29284556
Also have tried put localhost in /etc/hosts file?
0
 

Author Comment

by:sacombank-sbs
ID: 29284899
No hard link, they are separated files . All settings are correct (localhosts, ip, ..)
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29285309
Can you tried this in /etc/nsswitch.conf file

hosts :    files     dns
ipnodes:   files

Without dns in the end at ipnodes?
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 29286229
According to the notes in /etc/nsswitch.conf:

"Note that IPv4 addresses are searched in all of the ipnodes databases before
searching the hosts databases."

Because in your /etc/nsswitch.conf have the following:

hosts :    files     dns
ipnodes:   files   dns

If it couldn't find it in ipnodes file, will go to dns. If you take out dns, it then will go to hosts file.

Hope this is the answer.
0
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 29334283
You can fix it like this:

Make sure that /etc/inet/hosts if a real file and not a link, and it has all the entries you need.
Then run these two commands as root:

echo /etc/inet/ipnodes | pkgchk -i - -f
echo /etc/hosts | pkgchk -i - -f

Don't forget the dash after the -i.
0
 
LVL 10

Expert Comment

by:neteducation
ID: 29781258
Original Solaris Setting are:

Before Solaris 8: There was only /etc/inet/hosts. /etc/hosts was a hard link to /etc/inet/hosts
Solaris 8 & 9: There was independant /etc/inet/hosts (for IPv4) and /etc/inet/ipnodes (for IPv6). If a name needed to be resolved, hosts was taken before inodes. /etc/hosts was a link to /etc/inet/hosts (hardlink though, so was not recognized by many people that it actually was a link)
Solaris 10 first few verserion: there was independant /etc/inet/hosts  (for IPv4) and /etc/inet/ipnodes (for IPv6). If a name needed to be resolved, ipnodes was taken before hosts (!!!). /etc/hosts was a link to /etc/inet/hosts
More or less current Solaris 10 Versions:
There is only one File: /etc/inet/hosts. /etc/inet/ipnodes and /etc/hosts are symbolic links to /etc/inet/hosts

So if you have them in a different way let me suggest to change back to the default. That will give you the least problems.
0
 

Author Comment

by:sacombank-sbs
ID: 29799770
but why although I have a host in /etc/hosts file, It still use DNS first ? If as you say, It takes ipnodes before hosts , It must see my hosts in hosts file instead of using DNS

When I set in my nsswitch.conf :
  hosts :   files  
  ipnodes : files dns

It could detect the host in my /etc/hosts file
But when I set in my nsswitch.conf :
  hosts : files   dns
  ipnodes : files dns

It took dns first and didn't detect host in my hosts file.
I must add host into  ipnodes file to work arround.
That's the problem which I don't know why.


0
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 29800924
When you had the host in the host file but not the ipnodes file, then the search order becomes:

ipnodes file, DNS, hosts file, DNS.

So, it looks in the ipnodes file, doesn't find the host, then checks DNS. The DNS naming service has it's own search rules, so it actually looks for several different hostnames depending on the contents of  your /etc/resolv.conf file. So, DNS finds an answer, although it is not theone you expected. Once it gets an answer, the search is stopped and the DNS answer is returned to the program. So the hosts
file is never consulted. With the getent command, it is starting with the hosts file, so it gets what you expected.

Is it clear now?
0
 
LVL 10

Expert Comment

by:neteducation
ID: 29800953
Ok, I need to be more precise:

If your /etc/hosts (which normally is a link to /etc/inet/hosts) and your /etc/inet/ipnodes (which in newer versions of solaris 10 a link to /etc/inet/hosts, but used to be just a simple independent file) are two different files (that is not one is a link to the other, or both to a thrid file), then this is what happens:

If your nsswitch.conf looks like this:
hosts :   files  
ipnodes : files dns

Then it goes tries to do it in the following order:
ipnodes/files ipnodes/dns hosts/files

In the first two it only searches for IPv6, therefore does not find it -> entry in hosts/files is taken.


If your nsswitch.conf looks like this:
  hosts : files   dns
  ipnodes : files dns

it trys to optimizpe, not querying the DNS-Server twice and therefore it tries like this:
ipnodes/files dns(both V6 and V4) hosts/files

In your situation this makes it a bit confusing , but name services lookup is something where you can spend a lot of time, slowing down applications, that's why sun has on the one hand the nscd (name service cache daemon) and on the other hand optimizations like this.
0
 

Author Comment

by:sacombank-sbs
ID: 30018452
The explanation of neteducation seems be right . Is It true as the way Solaris 10 work ?
0
 
LVL 10

Accepted Solution

by:
neteducation earned 1000 total points
ID: 30021801
I'm not completly sure if the first view version of Solaris 10 have already done like this, but at least since Solaris 10 U5 (aka Solaris 10 5/08) it has been like this.
0
 

Author Closing Comment

by:sacombank-sbs
ID: 31708944
Closed , 250 points.
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 30139440
I have already provided the right answer on 31/03, but did not get any credit !!!
0
 

Author Comment

by:sacombank-sbs
ID: 30156049
I'm sorry because your answer wasn't right with my issue because you said that "if it couldn't find it in ipnodes file, will go to dns. If you take out dns, it then will go to hosts file." . But actually , It can use hosts file first (instead of use dns of ipnodes) if I use:
hosts:  files
ipnodes:  files dns

This question is closed here.
Thank you for your all support
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 30158432
Thats because you copied hosts file over to ipnodes

I fixed the problem by :
cat /etc/hosts >> /etc/inet/ipnodes
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

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…
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses
Course of the Month6 days, 20 hours left to enroll

593 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