Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
droplet discovery over digitalocean private networks

Digital Ocean recently released private networking support in their NYC2 Data center.

They also published a blog post on how to setup a new droplet with private networking. But one thing the post doesn't do is tell you how to scale your private network for many boxes. One approach is obviously to edit /etc/hosts (but this gets annoying when you add a new box). A better way is to create an internal DNS zone (via the digital ocean web interface) and have your droplets use it:


setup the internal DNS zone file

  1. Login to digital ocean
  2. Click "DNS" on the right hand menu
  3. Click "Add Domain"
  4. Name it "" (obviously use whatever TLD you want).
  5. Click "Create Domain"
  6. For each droplet you want resolved by name, add an A record with the droplet hostname and private IP.

Using doctl & jq:

  1. Get a list of each droplet (assuming their name contains the domain) and it's private ip:

    doctl d l | grep | awk '{print $2 }' | xargs -L 1 -P 5 doctl -f json d f | jq -r '.name as $host_name | .networks.v4[] | select(.type == "private")  | "\($host_name) \(.ip_address)"'

    Explanation: this uses xargs with the -L flag to parse each incoming line and -P to send parallel requests, jq is used to store the hostname in a variable and filter the ipv4 networks down to private types and only return the raw (-r) ip_address

  2. create a domain

    doctl dns c <droplet-name>
  3. Add records for each droplet with their private ip (from above listing)

    doctl dns add --name <droplet-name> --data <private-ip>

configure droplets (ref: private dns tutorial)

On each Ubuntu/Debian Droplet you create the head file, which is prepended to resolv.conf on boot to use the IP addresses of digital ocean nameserves (,, (note these may change)) as well as google nameservers

sudo vi /etc/resolvconf/resolv.conf.d/head

More info on search option, you may overwrite the search option from resolv conf using ping host1 this will try to resolve with the nameservers provided.

Now run resolvconf to generate a new resolv.conf file:

sudo resolvconf -u


Now all of your droplets can ping one another by hostname over the private network. And when you add a new droplet, just add it to the internal DNS zone and it will be visible by other droplets.

Copy link

EthraZa commented Jul 15, 2021

I have just created a shell script that works with latest doctl version 1.62.0-release and does not use jq

Thank you @so0k for the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment