LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can I use my /etc/hosts file as a person DNS server? (http://www.linuxquestions.org/questions/linux-newbie-8/can-i-use-my-etc-hosts-file-as-a-person-dns-server-713656/)

trist007 03-22-2009 07:17 PM

Can I use my /etc/hosts file as a person DNS server?
 
I only normally visit around 10 sites tops when surfing the net. Can I just include all the entries in the /etc/hosts file? So in theory, if I did this, and I only visited those 10 sites for the rest of my life, my computer would never access my ISP's name servers to resolve one of the domain names that I have listed in my /etc/hosts file? Also, if I connected wirelessly to my router, would there be any need for

echo "nameserver 192.168.1.1" > /etc/resolv.conf

?

Also, if the /etc/hosts file does do what I'm thinking it does, is there a file equivalent to the hosts file but on windows xp?

John VV 03-22-2009 07:19 PM

why not just use " OpenDNS " http://www.opendns.com/

trist007 03-22-2009 08:18 PM

If I just use those 10 sites, then wouldn't I get better performance on resolving?

Tinkster 03-22-2009 08:33 PM

Quote:

Originally Posted by trist007 (Post 3484422)
I only normally visit around 10 sites tops when surfing the net. Can I just include all the entries in the /etc/hosts file? So in theory, if I did this, and I only visited those 10 sites for the rest of my life, my computer would never access my ISP's name servers to resolve one of the domain names that I have listed in my /etc/hosts file?

Unless their IP addresses change or they get taken down
that should work just fine.

Quote:

Originally Posted by trist007 (Post 3484422)
Also, if I connected wirelessly to my router, would there be any need for

echo "nameserver 192.168.1.1" > /etc/resolv.conf

?

If you're not using DNS at all you wouldn't need your
router to be a server... how come you have to echo this,
though? Is it not handing out a new resolv.conf as part
of dhcp? Is it overwriting it with non-sensical data?

Quote:

Originally Posted by trist007 (Post 3484422)
Also, if the /etc/hosts file does do what I'm thinking it does, is there a file equivalent to the hosts file but on windows xp?

There should be a file lmhosts under the windows directory
somewhere, but I'm not a windows guy ...

billymayday 03-22-2009 08:36 PM

I think the windows version is is just hosts as well. Just search for it, since it's location seems to vary

trist007 03-22-2009 09:58 PM

If I'm using dns and I have all the domain entries in /etc/hosts for that computer, then there's no need to use my router for dns right?

Yea the echo thing is just a habit, hehe.

Also, let's say the above is true, can I setup all my other computers in my network to use ip address of this computer with /etc/hosts file for dns? I would just make sure port 53 is open on the computer with the /etc/hosts file.

Tinkster 03-23-2009 12:18 AM

Quote:

Also, let's say the above is true, can I setup all my other computers in my network to use ip address of this computer with /etc/hosts file for dns? I would just make sure port 53 is open on the computer with the /etc/hosts file.
Nope, that ain't gonna fly ... it's just a file, meant for local
lookups. If you want the machine to serve IPs to other boxes on
the local network you'll need some sort of DNS server process.


Quote:

If I'm using dns and I have all the domain entries in /etc/hosts for that computer, then there's no need to use my router for dns right?
Correct (as long as there's no changes of DNS for the machines you're
trying to connect to using the info in your hosts file).


Cheers,
Tink

salasi 03-23-2009 03:55 AM

Quote:

Originally Posted by Tinkster (Post 3484614)
Nope, that ain't gonna fly ... it's just a file, meant for local
lookups. If you want the machine to serve IPs to other boxes on
the local network you'll need some sort of DNS server process.

I think that you could sort-of make it work (not quite sure why you would want to....you sound like a candidate for pdns, dnsmasq, maradns, djbdns.. all of which will avoid the problem of ip addresses changing and give you, in general, reasonably quick look-up times).

If you run squid on the 'server' as a proxy, dns look up occurs local to squid rather than local to your browser and if squid is running on the machine with the doctored hosts file, that should give you what you seem to want. Plus caching, of course, which may not be a big win, but it is probably a small win all on its own.

Note that this would only work with things like the browser that use squid's proxying capabilities; this doesn't include things like command line utilities (ping, etc) and might not include some utilities that have similar ca[pabilities to ping or even some browser-like things that can't be set up to use the proxy (rss viewers?).

JaksoDebr 03-23-2009 04:58 PM

You can use /etc/hosts for a lot more sites then 10. With web browsers doing their caching anyway, you could use even hundred entries in /etc/hosts, and still not notice a difference. It is more likely to wait for the remote server to respond, then to wait for your local PC to look-up domains/IPs from /etc/hosts.

I use /etc/hosts entries for local testing of websites, that I'm working on. It's an easy way to switch between the remote server and the local development version, without messing up anything on the production. Having 20-30 such entries hasn't caused problems.

Linux Archive


All times are GMT -5. The time now is 10:45 PM.