github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/docs/examples.md (about) 1 --- 2 layout: default 3 title: Examples 4 --- 5 6 # Examples 7 8 * TOC 9 {:toc} 10 11 ## Typical DNS Records 12 13 {% highlight javascript %} 14 15 D('example.com', REG, DnsProvider('GCLOUD'), 16 A('@', '1.2.3.4'), // The naked or 'apex' domain. 17 A('server1', '2.3.4.5'), 18 AAAA('wide', '2001:0db8:85a3:0000:0000:8a2e:0370:7334'), 19 CNAME('www', 'server1'), 20 CNAME('another', 'service.mycloud.com.'), 21 MX('mail', 10, 'mailserver'), 22 MX('mail', 20, 'mailqueue'), 23 TXT('the', 'message'), 24 NS('department2', 'ns1.dnsexample.com.'), // use different nameservers 25 NS('department2', 'ns2.dnsexample.com.') // for department2.example.com 26 ) 27 28 {% endhighlight %} 29 30 ## Set TTLs 31 32 {% highlight javascript %} 33 34 var mailTTL = TTL('1h'); 35 36 D('example.com', registrar, 37 NAMESERVER_TTL('10m'), // On domain apex NS RRs 38 DefaultTTL('5m'), // Default for a domain 39 40 MX('@', 5, '1.2.3.4', mailTTL), // use variable to 41 MX('@', 10, '4.3.2.1', mailTTL), // set TTL 42 43 A('@', '1.2.3.4', TTL('10m')), // individual record 44 CNAME('mail', 'mx01') // TTL of 5m, as defined per DefaultTTL() 45 ); 46 47 {% endhighlight %} 48 49 ## Variables for common IP Addresses 50 51 {% highlight javascript %} 52 53 var addrA = IP('1.2.3.4') 54 55 D('example.com', REG, DnsProvider('R53'), 56 A('@', addrA), // 1.2.3.4 57 A('www', addrA + 1), // 1.2.3.5 58 ) 59 {% endhighlight %} 60 61 ## Variables to swap active Data Center 62 63 {% highlight javascript %} 64 65 var dcA = IP('5.5.5.5'); 66 var dcB = IP('6.6.6.6'); 67 68 // switch to dcB to failover 69 var activeDC = dcA; 70 71 D('example.com', REG, DnsProvider('R53'), 72 A('@', activeDC + 5), // fixed address based on activeDC 73 ) 74 {% endhighlight %} 75 76 ## Macro to for repeated records 77 78 {% highlight javascript %} 79 80 var GOOGLE_APPS_RECORDS = [ 81 MX('@', 1, 'aspmx.l.google.com.'), 82 MX('@', 5, 'alt1.aspmx.l.google.com.'), 83 MX('@', 5, 'alt2.aspmx.l.google.com.'), 84 MX('@', 10, 'alt3.aspmx.l.google.com.'), 85 MX('@', 10, 'alt4.aspmx.l.google.com.'), 86 CNAME('calendar', 'ghs.googlehosted.com.'), 87 CNAME('drive', 'ghs.googlehosted.com.'), 88 CNAME('mail', 'ghs.googlehosted.com.'), 89 CNAME('groups', 'ghs.googlehosted.com.'), 90 CNAME('sites', 'ghs.googlehosted.com.'), 91 CNAME('start', 'ghs.googlehosted.com.'), 92 ] 93 94 D('example.com', REG, DnsProvider('R53'), 95 GOOGLE_APPS_RECORDS, 96 A('@', '1.2.3.4') 97 ) 98 99 {% endhighlight %} 100 101 ## Add comments along complex SPF records 102 103 You normally can't put comments in the middle of a string, 104 but with a little bit of creativity you can document 105 each element of an SPF record this way. 106 107 {% highlight javascript %} 108 109 var SPF_RECORDS = TXT('@', [ 110 'v=spf1', 111 'ip4:1.2.3.0/24', // NY mail server 112 'ip4:4.3.2.0/24', // CO mail server 113 'include:_spf.google.com', // Google Apps 114 'include:mailgun.org', // Mailgun (requested by Ticket#12345) 115 'include:servers.mcsv.net', // MailChimp (requested by Ticket#54321) 116 'include:sendgrid.net', // SendGrid (requested by Ticket#23456) 117 'include:spf.mtasv.net', // Desk.com (needed by IT team) 118 '~all' 119 ].join(' ')); 120 121 D('example.com', REG, DnsProvider('R53'), 122 SPF_RECORDS, 123 ) 124 125 {% endhighlight %} 126 127 ## Dual DNS Providers 128 129 {% highlight javascript %} 130 131 D('example.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD'), 132 A('@', '1.2.3.4') 133 ) 134 135 // above zone uses 8 NS records total (4 from each provider dynamically gathered) 136 // below zone will only take 2 from each for a total of 4. May be better for performance reasons. 137 138 D('example2.com', REG, DnsProvider('R53',2), DnsProvider('GCLOUD',2), 139 A('@', '1.2.3.4') 140 ) 141 142 // or set a Provider as a non-authoritative backup (don't register its nameservers) 143 D('example3.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD',0), 144 A('@', '1.2.3.4') 145 ) 146 147 {% endhighlight %} 148 149 ## Set default records modifiers 150 151 {% highlight javascript %} 152 153 DEFAULTS( 154 NAMESERVER_TTL('24h'), 155 DefaultTTL('12h'), 156 CF_PROXY_DEFAULT_OFF 157 ); 158 159 {% endhighlight %}