Can I use my /etc/hosts file as a person DNS server?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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
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 ...
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.
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).
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?).
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.