Adding to /etc/hosts does not let clients resolve address

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
jstrauss
DD-WRT Novice


Joined: 17 Jun 2006
Posts: 41

PostPosted: Wed Jun 28, 2006 15:04    Post subject: Adding to /etc/hosts does not let clients resolve address Reply with quote
Hi,

I'm using the VPN version on 6/15/2006 on a wrt54GS v3. I would think if I added an entry to my /etc/hosts (on the wrt), that my clients would be able to ping by that name. But my WRT does not seem to be performing DNS resolution for my clients.

Stated differently, I did:

echo "192.168.1.30 zinc" >> /etc/hosts

on my WRT. Then from a client machine I said:

ping zinc

And it comes up unresolved. Anyone know why?

Thanks
Jay
Sponsor
WaS
DD-WRT Guru


Joined: 06 Jun 2006
Posts: 731
Location: Erlangen, Germany

PostPosted: Wed Jun 28, 2006 16:06    Post subject: Reply with quote
When the so-called "resolver" on the client contacts a DNS server to resolve a name
such as "zinc", it does not simply ask for "zinc". Instead, it adds a "." (dot) followed
by a domain name. When the client OS is Un*x, this is the domain name set by the
"search" keyword in the /etc/resolv.conf file. (Don't ask me how it works on Win!)
The bad thing is: When no domain name is specified, the resolver will still add the dot.

You can verify this by trying "ping zinc." or "ping zinc.local" (or whatever domain is
specified on the client.) This should work, because the resolver will not add the domain,
when at least one dot is already present in the name to be resolved..

To fix the problem, identify the domain set on your client machine(s); if it's empty, set
it to "local" or "localnet". On the router, the record for "zinc" should specify the host
name both with and without the domain, e.g.
Code:

192.168.1.30 zinc zinc.local
jstrauss
DD-WRT Novice


Joined: 17 Jun 2006
Posts: 41

PostPosted: Wed Jun 28, 2006 20:57    Post subject: Reply with quote
I did try to ping both:
zinc
zinc.

Clients are M$ (of course :)

I'll play with it again tonight hopefully, and post more unimportant information :)

Jay
GrumpY54gsv4
DD-WRT User


Joined: 07 Jun 2006
Posts: 286

PostPosted: Thu Jun 29, 2006 7:00    Post subject: Reply with quote
/etc/hosts is a read only file I thinks. You can add dns entries with the web interface.
kr4mm
DD-WRT Novice


Joined: 28 Jun 2006
Posts: 6
Location: Douglasville, GA

PostPosted: Thu Jun 29, 2006 9:33    Post subject: DNS lookups referencing the /etc/hosts file? Reply with quote
i don't recall DNSMasq looking in the /etc/hosts file before querying the DNS for a hostname. i thought only the wrt os would use the /etc/hosts file, and any queryies to it would be passed on to the up-level DNS server, regardless of what entries the /etc/hosts might contain.

maybe something has changed, or i'm completely wrong. i run my own DNS for this reason.
WaS
DD-WRT Guru


Joined: 06 Jun 2006
Posts: 731
Location: Erlangen, Germany

PostPosted: Thu Jun 29, 2006 9:43    Post subject: Re: DNS lookups referencing the /etc/hosts file? Reply with quote
kr4mm wrote:
i don't recall DNSMasq looking in the /etc/hosts file
before querying the DNS for a hostname. [...]

just try it out!
NB: /etc/hosts is not read-only
scmasaru
DD-WRT Novice


Joined: 29 Jun 2006
Posts: 1

PostPosted: Thu Jun 29, 2006 18:02    Post subject: Solved Reply with quote
just add the line
Code:
expand-hosts

to dnsmasq additional options field. It will automatiocally attach domain to the entries in the hosts file during look up.
purachochada
DD-WRT Novice


Joined: 19 Oct 2006
Posts: 7
Location: Nicaragua

PostPosted: Wed Nov 22, 2006 23:40    Post subject: dnsmasq using /etc/hosts for static DNS Reply with quote
The problem is that dnsmasq is loading the contents of /etc/hosts or /tmp/hosts (that's where /etc/hosts points to) during booting.
Any changes, applied to the hosts file, after booting, don't take effect for dnsmasq until the next reboot (note: as /etc/hosts is the hosts file for the router itself, the router can ping nodes applied after booting but not the dnsmasq process).

Unfortunately, any changes applied to the /etc/hosts file are lost if the router is shutdown (the /tmp is in RAM) which makes /etc/hosts useless for static DNS.

To solve this issue use the 'addn-hosts' option of dnsmasq to point to a file similar to the /etc/hosts located in /JFFS. Keep in mind that /JFFS needs to be activated (Web-GUI) prior of using!
An other possibility is using the dnsmasq --address= option (even it's original purpose is/was different)

So in the Web-GUI in Additional DNS Options put the following:
Code:
expand-hosts
addn-hosts=/jffs/tmp/hosts

In this case the /jffs/tmp/hosts file could look like:
Code:
192.168.1.30 zinc zink.your-domain

If using the dnsmasq --address= option, the value in Additional DNS Options would be:
Code:
address=/zinc.your-domain/192.168.1.30

It's possible to put several 'address' entries.

For further questions of dnsmasa use dnsmasq --help within at the command prompt.
JohnnyPrimus
DD-WRT User


Joined: 26 Oct 2006
Posts: 369

PostPosted: Wed Nov 22, 2006 23:45    Post subject: Reply with quote
To use /etc/hosts for static DNS stuff, add the following in a startup script:

cat /etc/hosts > /tmp/newhosts
echo "192.168.1.30 zinc" >> /tmp/newhosts
echo "192.168.1.31 otherhost" >> /tmp/newhosts
mount --bind /tmp/newhosts /etc/hosts


That said, the dnsmasq stuff above seems like a more elegant solution.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum