[Dnsmasq-discuss] dnsmasq.conf equivalent for /etc/hosts entry

Tom Metro tmetro+dnsmasq at gmail.com
Thu Oct 20 19:28:46 BST 2011


I'm running Dnsmasq 2.57 on a router where it is inconvenient to modify
the contents of the /etc/hosts file[1], but I'd like to achieve the
equivalent behavior for a few addresses, such as the static IP for my
gateway, which isn't in DNS and has no PTR record.

This is easy to do in /etc/hosts:
x.x.x.1 gw-lan
x.x.x.2 gw-wan

But it appears the equivalent for the config file is:
address=/gw-lan.mydomain/[alias...]/x.x.x.1
address=/gw-wan.mydomain/[alias...]/x.x.x.2
ptr-record=1.x.x.x.in-addr.arpa,gw-lan.mydomain
ptr-record=2.x.x.x.in-addr.arpa,gw-wan.mydomain

where PTR records have to be explicitly specified separately. Is this
correct? (Experimentally proven to be true.)

Is there no config directive that provide the direct equivalent to an
/etc/hosts entry? (I'm guessing you can likely fake it with a dhcp-host
directive, given its flexibility, though it would be a misleading use of
it, as it is unrelated to DHCP.)

Should there be?

I also see in the man page:

  -E, --expand-hosts
    Add the domain to simple names (without a period) in /etc/hosts in
    the same way as for DHCP-derived names. Note that this does not
    apply to domain names in cnames, PTR records, TXT records etc.

So unlike /etc/hosts and dhcp-host entries, I have to fully qualify each
host name with the local domain. This seems like unnecessary repetition.

On a side note, the documentation for ptr-record:

  --ptr-record=<name>[,<target>]
    Return a PTR DNS record.

is misleading, and too terse. From that, I expected the format to be:
ptr-record=gw-lan.mydomain,x.x.x.1

where <name> is the domain name, and <target> is the target IP. I never
would have guessed, had I not found examples online, that you had to
supply them in the opposite order, and that you had to put the address
in in-addr.arpa format.

It isn't obvious to me why you wouldn't use a simple IP address, but I
see in the example config file a case where <name> isn't an IP address
at all. Does that mean ptr-record has a less friendly syntax just so it
can accommodate some strange use case where you do PTR lookups on non-IP
addresses? Would that be better served by a different config directive?

What does ptr-record return if you omit the <target>, which apparently
is optional?

I recommend replacing <name> and <target> placeholders with something
more descriptive, including an example in the man page, and documenting
what happens when <target> is omitted.

 -Tom

1. Modifying the /etc/hosts file is doable, but creates a less
self-documenting setup, as a portion of the DNS/DHCP setup is now
stashed in some other part of the router GUI that deals with
miscellaneous scripts.

-- 
Tom Metro
Venture Logic, Newton, MA, USA
"Enterprise solutions through open source."
Professional Profile: http://tmetro.venturelogic.com/



More information about the Dnsmasq-discuss mailing list