Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CNAME aliases with dnsmasq

25,865 views
Skip to first unread message

Tom Anderson

unread,
Sep 10, 2010, 9:08:53 AM9/10/10
to
Hi,

I'd like to set up a hostname alias in an office network which uses
dnsmasq for DNS and DHCP. We have a machine called server-01 (well, not
exactly, but YKWIM) which gets its address through DHCP. I would like to
arrange it so that the hostname 'cvs' (or 'cvs.ouroffice.local' in full)
refers to this machine - and that it's still findable as server-01.

Preliminary question: is there any way i can get dnsmasq to pick up
changes to dnsmasq.conf without restarting it? I believe SIGHUP doesn't do
it - the man page states:

SIGHUP does NOT re-read the configuration file.

Restarting is fairly quick, so it's not fatal if there isn't.

Main question: how do i set up an alias? From reading the man page, notes
in dnsmasq.conf, and some stuff on the web, it seems like i should just be
able to add a line like this:

cname=cvs,server-01

to my dnsmasq.conf, and it should all just work. However, it doesn't. As
far as i can tell, it has no effect at all. I've restarted dnsmasq, i've
released and re-acquired the DHCP lease on server-01 (and seen the
timestamp on the entry in dnsmasq.leases change), and i still can't see a
machine called cvs.

What am i doing wrong?

Cheers,
tom

--
COUGH UP THE BENJAMINS FOR THE CYCLE-HELMETED PIMP DADDY! -- tNToEP

Chris Davies

unread,
Sep 11, 2010, 3:48:50 PM9/11/10
to
Tom Anderson <tw...@urchin.earth.li> wrote:
> I'd like to set up a hostname alias in an office network which uses
> dnsmasq for DNS and DHCP. We have a machine called server-01 (well, not
> exactly, but YKWIM) which gets its address through DHCP. I would like to
> arrange it so that the hostname 'cvs' (or 'cvs.ouroffice.local' in full)
> refers to this machine - and that it's still findable as server-01.

> cname=cvs,server-01

This looks correct, provided that dnsmasq already knows about
server-01. At least, it worked for me when I tried it on a sample setup
just now.

Chris

Tom Anderson

unread,
Sep 12, 2010, 7:02:01 AM9/12/10
to

Thanks for trying it. Any theories on why it wouldn't work for me?

I wondered if it was because the client wasn't using dnsmasq as a DNS
server, but it sees server-01 fine, so it must be. I wondered if it was
because server-01 wasn't getting its address via DHCP, but i tried a
couple of machines, saw the entry in the lease file, etc.

It's probably time to check the logs.

tom

--
Give the future a chance!

Chris Davies

unread,
Sep 12, 2010, 4:45:07 PM9/12/10
to
Tom Anderson <tw...@urchin.earth.li> wrote:
> Thanks for trying it. Any theories on why it wouldn't work for me?

Sorry, none. (I don't really use dnsmasq, here.)
Chris

Tom Anderson

unread,
Sep 13, 2010, 1:50:49 PM9/13/10
to

Thanks anyway.

On the bright side, i have discovered what the problem was, and fixed it.

To recap, i have a line like:

cname=cvs,server-01

In my dnsmasq.conf.

Problem one was the way i was testing that the alias had been set up. I'd
been doing:

ping cvs

And occasionally:

getent hosts cvs

What i hadn't tried is:

dig @dnsmasq-server cvs

As soon as i did that, i got a hit, a very palpable hit:

;; ANSWER SECTION:
cvs. 0 IN CNAME server-01.
server-01. 0 IN A 192.168.1.86

So, dnsmasq is serving that CNAME perfectly well. The problem is with my
local resolver. Have you guessed what the problem is yet?

Something else i tried, through inaccurate copy-paste, was:

ping cvs.

And that *worked*. Now, as any fule kno, the dot at the end of a domain
name indicates that it is the end of the domain name - there are no more
name segments to come. Whereas without a dot, it's a local name, which is
interpreted relative to the current domain. Which according to my
/etc/resolv.conf:

# Generated by NetworkManager
domain tom.office
search tom.office
nameserver 192.168.1.250

is tom.office. So, when i try to get to cvs, i'm really trying to get to
cvs.tom.office.

Now, my dnsmasq.conf contains a line:

domain=tom.office

Which got sent by dnsmasq in the DHCP lease to my local machine, where
NetworkManager duly wrote it down in resolv.conf. But it seems that
dnsmasq does *not* append that suffix to cnames. That's fair, i suppose;
if i want to alias www.vatican.va to a server of my own, then adding my
domain to that would be inappropriate. I would suggest that it would be
more useful if it applied the same heuristic as name lookup, ie add the
domain if there's no dot in the name, but i imagine Mr Kelley would
disagree.

Anyway, if i change the line in dnsmasq.conf to:

cname=cvs.tom.office,server-01

Then this:

ping cvs

works. Solved!

Oh, and there was nothing of any use at all in the logs, by the way.

tom

--
But in the week its like Urbino under the wise rule of Count Federico,
only with a better football team and the nations most pleb-infested
Waitrose. And shops selling size 12 stilettos. -- Jelb, on Holloway

Tom Anderson

unread,
Sep 13, 2010, 2:01:35 PM9/13/10
to
On Mon, 13 Sep 2010, Tom Anderson wrote:

> To recap, i have a line like:
>
> cname=cvs,server-01
>
> In my dnsmasq.conf.
>

> [...]


>
> Now, my dnsmasq.conf contains a line:
>
> domain=tom.office

Addendum: even if i set expand-hosts, this combination doesn't create an
entry for cvs.tom.office. I have to write the domain out longhand in the
cname entry.

Chris Davies

unread,
Sep 14, 2010, 4:24:14 AM9/14/10
to
Tom Anderson <tw...@urchin.earth.li> wrote:
> On the bright side, i have discovered what the problem was, and fixed it.

[excellent summary deleted]

Very good point. I'd started with the (Debian?) example dnsmasq.conf,
and chopped it to fit. This left me with four lines:

# dnsmasq -d -k -p 60053 # dig -p 60053 ...

domain-needed
expand-hosts
domain=tom.office
cname=bertand.tom.office,smartboard # smartboard is in /etc/hosts

Originally, the last line had been an unqualified name, but for some
reason that I can't fathom, cnames aren't handled with the expand-hosts
directive:

cname=bertand,smartboard # broken

Pleased to hear you've found the issue.

Regards,
Chris

fren...@gmail.com

unread,
Nov 14, 2013, 12:24:47 PM11/14/13
to
You're a life saver Tom!

Thanks a bunch!
0 new messages