RHEL name resolution

Hi,

How do I force a RHEL server to always use the local host file before attempting to send the request to a DNS server ?

Thanks
Elemental12Asked:
Who is Participating?
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
I still think it's situational, and hosts is an entirely legitimate mechanism (for far more than testing). But it's very true to say (as Papertrip has) that if an application has it's own resolver, and that's what you're trying to tweak, no amount of messing with hosts will help.

Chris
0
 
PapertripCommented:
Should be that way by default, but if not then change the 'hosts' line in /etc/nsswitch.conf

hosts:    files dns
0
 
Elemental12Author Commented:
yup, checked that already, and the file shows:

hosts:      files dns

but for some reason, when I do an nslookup, even if I know the name is wrong, it checks the DNS servers.  For one particular host name, I need it to check the local hosts file, as I do not want it to exist on my DNS servers.
0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
Chris DentPowerShell DeveloperCommented:
NsLookup is a debugging tool, it doesn't use the client resolver (whether that's RHEL or any other OS), it queries DNS directly and only.

If you want to test the client, use Ping, or telnet, or something else that relies on the computer to do name resolution.

Chris
0
 
PapertripCommented:
nslookup doesn't honor the hosts file, use ping or telnet to test instead.
0
 
James HIT DirectorCommented:
Do you have Bind installed??
this would work to help resolve names locally.

http://www.experts-exchange.com/Networking/Linux_Networking/Q_26812340.html?sfQueryTermInfo=1+10+30+kennyhenao
0
 
Elemental12Author Commented:
ahhh, thank you all for telling me that.  How do I go about testing reverse name lookup via an application ?  pinging by IP, just pings by IP, does not give me the host name.
0
 
Elemental12Author Commented:
I found ping -a for windows ... just looking for the RHEL equivalent
0
 
PapertripCommented:
Are you asking just how to do a reverse DNS lookup in Linux?

dig -x ip.address
host ip.address
nslookup ip.address

Open in new window

0
 
PapertripCommented:
dig is part of the bind-utils package, so you probably don't have it installed by default, but I recommend it above the other 2 options when possible.
0
 
Elemental12Author Commented:
well, I need a way to do a reverse dns lookup to prove that this server is using the host file first, and DNS second.  I need to use something that honors the host file, as stated above.  Nslookup does not look at the host file as stated above.  I need to prove that this server is using the host file first, and the DNS server second.  How can I prove this ?  I have a fake dns record in my local host file, but when I try to nslookup that fake DNS record, it tries to go to the DNS server to resolve it.  I don't want that.
0
 
PapertripConnect With a Mentor Commented:
Is there a specific reason you need to fake the IP as well as the hostname?  I think some of the confusion on this thread from the experts side is that we don't know exactly why you are trying to do this.

All you can "prove" with any of this testing is whether a certain application (ping, nslookup, host) honors /etc/hosts.  Proving that everything on the server is using it, that would be a pain and probably not worth the time.

If you need to fake both forward and reverse lookups to make sure that every single query for a specific hostname/ip gets the fake results, no matter what sends the query, then you need to setup a DNS server with fake zones for any host/ip you want to modify.

0
 
Elemental12Author Commented:
Yes, I am adding a host to the local host file because I do not want to create an entire dns server or zone for just one host.

yes, all I want to prove is that if I put in an IP address in my local hosts file, any name resolution will respect what is in the host file first, and DNS second.  So for example if my host file has

172.16.1.1      fake1.domain.com

but DNS server has 172.16.1.1 as real1.domain.com, when the server goes to 172.16.1.1, I want it to believe the name that belongs to that IP is fake1.domain.com
0
 
Chris DentPowerShell DeveloperCommented:
Both forward and reverse (should) load into the client cache from hosts by default, you might try enabling debugging with nscd (perhaps). Not a Unix / Linux expert so I don't have a reasonable suggestion beyond that.

Chris
0
 
Elemental12Author Commented:
I was thinking of restarting nscd, which would clear cache, but higherups were not happy with that idea.
0
 
James HIT DirectorCommented:
Linux doesn't work that way with DNS.
You can't use HOST file for name resolution.
You will have to setup DNS for what you are asking for.
0
 
Elemental12Author Commented:
Linux does not use host files ?
0
 
James HIT DirectorCommented:
Yes, Linux does use host files but for what you are trying to do it will not work.
You cannot "trick" the OS into resolving a local name with a HOST entry.
You will need to setup DNS for this purpose.
0
 
Chris DentPowerShell DeveloperCommented:
Um, why not?

It's a name, it doesn't need a Hosts file entry and a DNS entry, it's not a trick, it's a legitimate name resolution technique.

Chris
0
 
Elemental12Author Commented:
Yes, the word "trick" is a bad word I am using ...

I have been able, in Windows anyway, to put in different names for the same IP and when that server does to any of those different names, the requests are set to the same IP.
0
 
PapertripCommented:
You can't prove that everything on the system that needs DNS resolution is going to honor the hosts file.  The way to do this is by serving up the fake zone file, but even then you may have an app using a built-in resolver that you can't control.

Making fake entries in /etc/hosts is generally used only temporarily and for testing/troubleshooting purposes.  Anything more than that should be done through DNS.
0
 
Elemental12Author Commented:
We found out it was a coding issue after all that was deciding the host name to IP, regardless of what I did in the host file.  I decided to split the points equally though due to the effort from both of you, and the accuracy of your answers.  Thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.