Giving preference to the hosts file

I need to test a website that is not ready for prime time. The domain name is not registered yet so it cannot be found with the DNS system.

I have added the IP address and domain name to the /etc/hosts file. The name does not resolve.

How do I have the local name lookup check the hosts file for name resolution?

Maybe look at /etc/nsswitch.conf (and it’s man page of course).

On 2014-09-09 21:26, jimoe666 wrote:
>
> I need to test a website that is not ready for prime time. The domain
> name is not registered yet so it cannot be found with the DNS system.
>
> I have added the IP address and domain name to the /etc/hosts file. The
> name does not resolve.

It can not “resolve”, but nevertheless, should be used. If you want it
to “resolve”, you need a local DNS, like dnsmasq. It simply reads your
host file and answers as DNS. Terribly easy to setup - it is in fact
installed by default in 13.1, but inactive, I think.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

By default and for me, results are immediate when I add an entry to the hosts file.
Unless your machine is custom configured otherwise, a lookup to the local hosts file is always performed before any other method (eg DNS lookup) so any entries in the hosts file will over-ride any other name resolution mappings.

So,
Your problem is not likely whether the lookup to the hosts file is being performed first, but one (or more) of the following

  • If the URL maps to a different address (used to point to a different IP address, then your name resolution cache needs to be flushed.
systemctl restart nscd
  • Your web browser may be displaying a cached version of the web page when you last saw an error. Reload/refresh the web page and to minimize this occuring, set your browser cache to zero or as low as possible. I typically install many web browsers on my Dev machine and configure one of them with these special dev-related settings.

  • If you are still having problems after the above, then you need to be more specific where you are seeing your problem, in a web browser or other. You can always check your machine level name resolution by using the nslookup utility.

  • Verify the entry is entered correctly. You can minimize errors by using YAST, verify your results using a text editor (or “cat” or “less” the file). If you are unsure of this and there is no security issue, post your hosts file for others to view.

dnsmasq should not be necessary, but if you have it installed then you may need to address issues related to it like clearing that cache as well.l

HTH,
TSU

Well, not so much solved as I have an alternate method.

Being the Sys Admin, I added a new zone to the DNS service (BIND, named) that has the one address to resolve. When I am done testing the new site, I will remove the zone.

That’s a common approach, particularly if you intend to set up permanent re-mappings or if you need to re-direct many hosts. I’ve sometimes set up special DNS to do specifically this, and then point specified hosts to these special DNS so that it doesn’t affect everybody.
In the hacking world, it’s called “DNS Poisoning” is something to guard against but as you might discover can be used for good, too.

TSU