Domain name to get local agent IP address

Hi all.

I know you can use the DNS interface to get a node’s IP using NODE_ID.node.DOMAIN
Is there any way to get the IP of the local agent such as local.node.DOMAIN?

I want to put it statically in a configuration file and resolve it at runtime to whatever IP the node is assigned.

Thanks.

Since I’m already using dnsmasq, in the end what I did is to add this line to dnsmasq configuration interface-name=local.n0de.cl4,eth0 This would resolve local.n0de.cl4 to whatever IP is associated with eth0 interface.

If there is any more elegant solution or if Consul already provides something similar please share it with me :slight_smile:

Hey @kouzant,

You could also use the node name to lookup nodes via DNS. If you’re following a pattern for naming the nodes, it could simplify templating this value in a config file a bit.

Unfortunately, you couldn’t look up the node info via DNS as you have suggested, but there is an HTTP endpoint v1/agent/self that has all agent information, including the node name, node ID and the IP address of the node. Note though that if you have ACLs enabled, this endpoint requires agent:read permissions.

I’m not sure though if this is more elegant, but hope this helps!

Cheers,
Iryna

1 Like

Hi @ishustava

The configuration file in which I want to use this “special reserved” domain name is baked into an image and cannot be changed afterwards.

Unfortunately I don’t have the privilege of changing the business logic to make an HTTP call to local agent so I’m kinda stuck with the solution I wrote above.

It might be useful for Consul to provide this functionality out of the box in a future version.

Nevertheless thanks for your reply.

Hi @kouzant!

Thank you for your question, and welcome to the Discuss forum! Have you by any chance, looked into consul-template? You should be able to update the image with a new config file that uses the templating engine, and pull in the domain to populate the config.

Our Learn track, to learn how the template engine runs:

Here is the blog post that introduced consul-template