Virtual Event
Join us for the next HashiConf Digital October 12-15, 2020 Register for Free

Cloud and Platform Integrations

Discover Services External to Pivotal Application Service

Pivotal Application Service (PAS) is a cloud-agnostic platform for running applications. It abstracts away the complexity of running your own infrastructure and networking for an application and gives developers the ability to focus on writing code. It has many features, including its own internal service discovery. In hybrid environments, where workloads can run on multiple platforms or clouds, applications running on PAS may need to discover services external to the platform.

Consul’s DNS interface is one of its primary querying interfaces for discovering external services. This introductory tutorial describes the basics on how to configure your PAS installation to delegate DNS lookups for Consul-specific domains to the Consul servers.


This tutorial assumes basic familiarity with Consul, PAS, as well as its tools, like BOSH and Ops Manager. You will be able complete this tutorial without production experience.

Here is what you will need for this tutorial:

  • A running installation of PAS
  • Ability to make and apply changes in Pivotal Ops Manager
  • Ability to push applications to PAS
  • IPs or DNS name(s) of the Consul servers that you will be connecting to

You will also need to ensure that the container host VMs (aka Diego VMs) have network connectivity to the Consul servers.

Consul DNS and PCF

»Configure PAS to use Consul DNS

Log in to your Pivotal Ops Manager instance, use Pivotal documentation for instructions specific to your installation.

From your installation dashboard navigate to the “BOSH DNS Config Page” within the BOSH Director tile.

Add the following configuration to the Handlers field, setting recursors to the IPs or DNS names of your Consul servers.

    "cache": {
      "enabled": true
    "domain": "consul.",
    "source": {
      "recursors": ["", "", ""],
      "type": "dns"

This configuration sets the Consul server running on and the default DNS port 8600.

If the Consul server is configured with a different domain, make sure to change the domain property above to reflect that.

Your resulting page should include the configuration in the Handlers field.


When ready, click "Save". Note that you will need to review and apply pending changes in Ops Manager to apply the configuration.

»Discover a service with Consul DNS

Now that you have configured Consul’s DNS as a query interface, you can test that it works by deploying a simple demo application. From the demo application container, you will be able to query Consul DNS.

First, log in to PAS.

$ cf login -a

Create an organization.

$ cf create-org hashicorp

Create a space.

$ cf create-space -o hashicorp consul-demo

Target an organization and a space.

$ cf target -o hashicorp -s consul-demo

Next, download the demo application.

$ git clone

Move into the directory for the downloaded app.

$ cd cf-sample-app-spring

Deploy the demo application.

$ cf push

The demo application is maintained by Cloud Foundry.

Finally, SSH into the demo application container and use dig to discover all running instances of the Consul service.

$ cf ssh cf-demo -c 'dig consul.service.consul'
; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> consul.service.consul
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62872
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 4
;; WARNING: recursion requested but not available

; EDNS: version: 0, flags:; udp: 4096
;consul.service.consul.      IN    A

consul.service.consul.    5    IN    A
consul.service.consul.    5    IN    A
consul.service.consul.    5    IN    A

consul.service.consul.    5    IN    TXT    "consul-network-segment="
consul.service.consul.    5    IN    TXT    "consul-network-segment="
consul.service.consul.    5    IN    TXT    "consul-network-segment="

;; Query time: 2 msec
;; WHEN: Thu Dec 05 07:04:34 UTC 2019
;; MSG SIZE  rcvd: 332

»Next steps

In this tutorial you learned how to configure Pivotal Application Service (PAS) to use Consul’s DNS interface for service discovery of external services. If you have services deployed in hybrid environments, such as VMs or Kubernetes, you will now be able to discover them using Consul’s DNS interface.

Learn more about Consul service discovery and registration and Consul’s DNS interface.