Fetching contributors…
Cannot retrieve contributors at this time
106 lines (74 sloc) 2.06 KB

Getting started with Fog::DNS and Dreamhost (2013/01/21)

You'll need a Dreamhost account and API key to use this.


Create an API key selecting 'All dns functions' to be able to add/remove/list records.

Create the service

We need to create the service first, using the API key from our account:

require 'fog'
require 'pp'

dh = :provider => "Dreamhost",
                   :dreamhost_api_key => '6SHU5P2HLDAYECUM' )

List all the DNS zones

This will list all the DNS zones avaialble in your account:

dh.zones.each do |zone|
  puts zone.domain

Retrieve all the records

List all the records available in your Dreamhost account, accross all the zones:

dh.records.each do |r|

If you want to fetch all the records in a single zone:

zone = dh.zones.get ''
zone.records.each do |r|
  # do something with the record


Retrieve a single record

Get a single record and do something with the attributes:

rec = dh.records.get ''
rec.type       # A, CNAME, TXT, etc       # zone the record belongs to
rec.account_id # Dreamhost account ID
rec.comment    # Record text comment
rec.value      # record value

Create a new A record

Let's create a new A record:

zone = dh.zones.get ''
zone.records.create :name => '',
                    :type => 'TXT',
                    :value => 'foobar bar bar'

Since Dreamhost API does not support the concept of zone, you can also use this code to accomplish the same thing:

  :name => '',
  :type => 'A',
  :value => ''

Destroy all the records in a zone

(dh.zones.get '').records.each do |rec|


The Dreamhost API:

DNS API commands: