Search code examples
dnsconsul

Removing 'node' sub-domain from middle of consul DNS lookup


I have a reasonably ephemeral environment, with machines running consul agent on startup and registering themselves as nodes.

As there are enough Consul servers I would like to use Consul DNS internally to locate machines.

The issue is that the machines are named somevm.example.com rather than somevm.node.consul

I can change the domain in the consul config file, but that still leaves the 'node' sub-domain in the middle of the lookup: somevm.node.example.com, which is not correct.

Can I coax consul into changing this? Or can I dynamically change this, (direct sub, dynamic CNAME etc), in some DNS server/Proxy that I am inevitably going to have to run to resolve on port 53 rather than 8600.


Solution

  • I was just investigating this a while back, currently it isn't possible to remove the node part using only Consul, however you can run coredns on port 53, proxying and rewriting requests to and from Consul by leveraging the rewrite plugin.

    The rewrite plugin documentation includes detailed examples on rewriting parts of the dns query and response and includes examples specific to Consul.

    Hope it helps.