Can Consul DNS provide the Nomad service port along with the IP address?

I have two Nomad jobs running in a Nomad cluster. One job needs to connect to the other job using the service address. This is because the target job is using whatever dynamic address/port that Nomad assigns to it.

The target job has a “service” defined: service-name-of-target-job

Nomad assigns the service and address similar to this: 10.254.0.37:64441

The source job tries to connect to the target service address using the Consul DNS address: service-name-of-target-job.service.consul. However, the connection times out.

Doing a curl from the source job I see this:

curl -v "http://service-name-of-target-job.service.consul/"
*   Trying 10.254.0.37:80...

As we can see, Consul DNS is only providing the IP address and not the dynamic port that is assigned, thus the source job is trying the default port 80, which is incorrect.

Is there a way to get the Consul DNS to provide the port as well as the IP? Or will I need to force the target job to use a static port?

I guess curl is not a good definitive test. Apparently within the service it is actually getting the correct port.

@SunSparc to get port numbers from DNS you need to use SRV records instead of the usual A/AAAA records.

E.g. looking up nomad-client service in a local Consul, I get

➜ dig @127.0.0.1 -p 8600 SRV nomad-client.service.consul

;; QUESTION SECTION:
;nomad-client.service.consul.   IN      SRV

;; ANSWER SECTION:
nomad-client.service.consul. 0  IN      SRV     1 1 4646 7f000001.addr.dc1.consul.

;; ADDITIONAL SECTION:
7f000001.addr.dc1.consul. 0     IN      A       127.0.0.1
diablo.node.dc1.consul. 0       IN      TXT     "consul-network-segment="

Unfortunately curl itself doesn’t support SRV records (and neither do most browsers).

You’d have to write a custom tool like srv-pls to do something useful with the results.