diff --git a/command/agent/dns.go b/command/agent/dns.go index ce434a948c..8575723325 100644 --- a/command/agent/dns.go +++ b/command/agent/dns.go @@ -201,7 +201,7 @@ func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) { if arpa == qName { ptr := &dns.PTR{ Hdr: dns.RR_Header{Name: q.Name, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: 0}, - Ptr: fmt.Sprintf("%s.node.%s.%s.", n.Node, datacenter, d.domain), + Ptr: fmt.Sprintf("%s.node.%s.%s", n.Node, datacenter, d.domain), } m.Answer = append(m.Answer, ptr) break diff --git a/command/agent/dns_test.go b/command/agent/dns_test.go index 6d1ca4f71c..4c713bb4c2 100644 --- a/command/agent/dns_test.go +++ b/command/agent/dns_test.go @@ -346,6 +346,49 @@ func TestDNS_ReverseLookup(t *testing.T) { } } +func TestDNS_ReverseLookup_CustomDomain(t *testing.T) { + dir, srv := makeDNSServer(t) + defer os.RemoveAll(dir) + defer srv.agent.Shutdown() + srv.domain = dns.Fqdn("custom") + + testutil.WaitForLeader(t, srv.agent.RPC, "dc1") + + // Register node + args := &structs.RegisterRequest{ + Datacenter: "dc1", + Node: "foo2", + Address: "127.0.0.2", + } + + var out struct{} + if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil { + t.Fatalf("err: %v", err) + } + + m := new(dns.Msg) + m.SetQuestion("2.0.0.127.in-addr.arpa.", dns.TypeANY) + + c := new(dns.Client) + addr, _ := srv.agent.config.ClientListener("", srv.agent.config.Ports.DNS) + in, _, err := c.Exchange(m, addr.String()) + if err != nil { + t.Fatalf("err: %v", err) + } + + if len(in.Answer) != 1 { + t.Fatalf("Bad: %#v", in) + } + + ptrRec, ok := in.Answer[0].(*dns.PTR) + if !ok { + t.Fatalf("Bad: %#v", in.Answer[0]) + } + if ptrRec.Ptr != "foo2.node.dc1.custom." { + t.Fatalf("Bad: %#v", ptrRec) + } +} + func TestDNS_ReverseLookup_IPV6(t *testing.T) { dir, srv := makeDNSServer(t) defer os.RemoveAll(dir)