2017-03-23 03:20:19 +08:00
|
|
|
## Typical DNS Records
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2017-03-23 03:20:19 +08:00
|
|
|
D('example.com', REG, DnsProvider('GCLOUD'),
|
|
|
|
A('@', '1.2.3.4'), // The naked or 'apex' domain.
|
|
|
|
A('server1', '2.3.4.5'),
|
|
|
|
AAAA('wide', '2001:0db8:85a3:0000:0000:8a2e:0370:7334'),
|
|
|
|
CNAME('www', 'server1'),
|
|
|
|
CNAME('another', 'service.mycloud.com.'),
|
2017-03-23 05:31:00 +08:00
|
|
|
MX('mail', 10, 'mailserver'),
|
2017-03-23 03:20:19 +08:00
|
|
|
MX('mail', 20, 'mailqueue'),
|
|
|
|
TXT('the', 'message'),
|
2019-05-21 10:33:50 +08:00
|
|
|
NS('department2', 'ns1.dnsexample.com.'), // use different nameservers
|
|
|
|
NS('department2', 'ns2.dnsexample.com.') // for department2.example.com
|
2017-03-23 03:20:19 +08:00
|
|
|
)
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2017-03-23 03:20:19 +08:00
|
|
|
|
2017-04-29 02:17:44 +08:00
|
|
|
## Set TTLs
|
2017-03-23 03:20:19 +08:00
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2019-05-21 10:33:50 +08:00
|
|
|
var mailTTL = TTL('1h');
|
|
|
|
|
2017-04-29 02:17:44 +08:00
|
|
|
D('example.com', registrar,
|
2019-05-21 10:33:50 +08:00
|
|
|
NAMESERVER_TTL('10m'), // On domain apex NS RRs
|
2017-06-09 02:14:46 +08:00
|
|
|
DefaultTTL('5m'), // Default for a domain
|
2019-05-21 10:33:50 +08:00
|
|
|
|
|
|
|
MX('@', 5, '1.2.3.4', mailTTL), // use variable to
|
|
|
|
MX('@', 10, '4.3.2.1', mailTTL), // set TTL
|
|
|
|
|
2017-06-09 02:14:46 +08:00
|
|
|
A('@', '1.2.3.4', TTL('10m')), // individual record
|
2019-05-21 10:33:50 +08:00
|
|
|
CNAME('mail', 'mx01') // TTL of 5m, as defined per DefaultTTL()
|
2017-04-29 02:17:44 +08:00
|
|
|
);
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2017-03-23 03:20:19 +08:00
|
|
|
|
2017-03-21 11:47:18 +08:00
|
|
|
## Variables for common IP Addresses
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2017-03-28 05:33:27 +08:00
|
|
|
var addrA = IP('1.2.3.4')
|
2017-03-21 11:47:18 +08:00
|
|
|
|
2017-03-28 05:33:27 +08:00
|
|
|
D('example.com', REG, DnsProvider('R53'),
|
2018-01-10 01:53:16 +08:00
|
|
|
A('@', addrA), // 1.2.3.4
|
|
|
|
A('www', addrA + 1), // 1.2.3.5
|
2017-03-21 11:47:18 +08:00
|
|
|
)
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2017-03-21 11:47:18 +08:00
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
{% hint style="info" %}
|
|
|
|
**NOTE**: The `IP()` function doesn't currently support IPv6 (PRs welcome!). IPv6 addresses are strings.
|
|
|
|
{% endhint %}
|
2022-10-28 04:16:37 +08:00
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2022-10-28 04:16:37 +08:00
|
|
|
var addrAAAA = "0:0:0:0:0:0:0:0";
|
|
|
|
```
|
|
|
|
|
2017-03-21 11:47:18 +08:00
|
|
|
## Variables to swap active Data Center
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2017-03-28 05:33:27 +08:00
|
|
|
var dcA = IP('5.5.5.5');
|
|
|
|
var dcB = IP('6.6.6.6');
|
2017-03-21 11:47:18 +08:00
|
|
|
|
|
|
|
// switch to dcB to failover
|
|
|
|
var activeDC = dcA;
|
|
|
|
|
2017-03-28 05:33:27 +08:00
|
|
|
D('example.com', REG, DnsProvider('R53'),
|
|
|
|
A('@', activeDC + 5), // fixed address based on activeDC
|
2017-03-21 11:47:18 +08:00
|
|
|
)
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2017-03-21 11:47:18 +08:00
|
|
|
|
2017-03-28 05:31:23 +08:00
|
|
|
## Macro to for repeated records
|
2017-03-21 11:47:18 +08:00
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2022-10-31 18:50:41 +08:00
|
|
|
var GOOGLE_APPS_MX_RECORDS = [
|
2017-03-21 11:47:18 +08:00
|
|
|
MX('@', 1, 'aspmx.l.google.com.'),
|
|
|
|
MX('@', 5, 'alt1.aspmx.l.google.com.'),
|
|
|
|
MX('@', 5, 'alt2.aspmx.l.google.com.'),
|
|
|
|
MX('@', 10, 'alt3.aspmx.l.google.com.'),
|
|
|
|
MX('@', 10, 'alt4.aspmx.l.google.com.'),
|
2022-10-31 18:50:41 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
var GOOGLE_APPS_CNAME_RECORDS = [
|
2017-03-28 05:37:41 +08:00
|
|
|
CNAME('calendar', 'ghs.googlehosted.com.'),
|
|
|
|
CNAME('drive', 'ghs.googlehosted.com.'),
|
|
|
|
CNAME('mail', 'ghs.googlehosted.com.'),
|
|
|
|
CNAME('groups', 'ghs.googlehosted.com.'),
|
|
|
|
CNAME('sites', 'ghs.googlehosted.com.'),
|
2017-03-28 05:31:23 +08:00
|
|
|
CNAME('start', 'ghs.googlehosted.com.'),
|
2017-03-21 11:47:18 +08:00
|
|
|
]
|
|
|
|
|
2017-03-28 05:33:27 +08:00
|
|
|
D('example.com', REG, DnsProvider('R53'),
|
2022-10-31 18:50:41 +08:00
|
|
|
GOOGLE_APPS_MX_RECORDS,
|
|
|
|
GOOGLE_APPS_CNAME_RECORDS,
|
2017-03-28 05:33:27 +08:00
|
|
|
A('@', '1.2.3.4')
|
2017-03-21 11:47:18 +08:00
|
|
|
)
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2017-03-21 11:47:18 +08:00
|
|
|
|
2023-02-19 23:59:03 +08:00
|
|
|
## Use SPF_BUILDER to add comments along SPF records
|
2017-03-28 05:41:28 +08:00
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2023-02-19 23:59:03 +08:00
|
|
|
D("example.tld", REG, DSP, ...
|
|
|
|
A("@", "10.2.2.2"),
|
|
|
|
MX("@", "example.tld."),
|
|
|
|
SPF_BUILDER({
|
|
|
|
label: "@",
|
|
|
|
overflow: "_spf%d",
|
|
|
|
raw: "_rawspf",
|
|
|
|
ttl: "5m",
|
|
|
|
parts: [
|
|
|
|
"v=spf1",
|
|
|
|
"ip4:198.252.206.0/24", // ny-mail*
|
|
|
|
"ip4:192.111.0.0/24", // co-mail*
|
|
|
|
"include:_spf.google.com", // GSuite
|
|
|
|
"~all"
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
);
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2017-03-28 05:41:28 +08:00
|
|
|
|
2017-03-21 11:47:18 +08:00
|
|
|
## Dual DNS Providers
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2017-03-28 05:33:27 +08:00
|
|
|
D('example.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD'),
|
|
|
|
A('@', '1.2.3.4')
|
2017-03-21 11:47:18 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// above zone uses 8 NS records total (4 from each provider dynamically gathered)
|
|
|
|
// below zone will only take 2 from each for a total of 4. May be better for performance reasons.
|
|
|
|
|
2017-03-28 05:33:27 +08:00
|
|
|
D('example2.com', REG, DnsProvider('R53',2), DnsProvider('GCLOUD',2),
|
|
|
|
A('@', '1.2.3.4')
|
2017-03-21 11:47:18 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// or set a Provider as a non-authoritative backup (don't register its nameservers)
|
2017-03-28 05:33:27 +08:00
|
|
|
D('example3.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD',0),
|
|
|
|
A('@', '1.2.3.4')
|
2017-03-21 11:47:18 +08:00
|
|
|
)
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2019-05-21 10:33:50 +08:00
|
|
|
|
|
|
|
## Set default records modifiers
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2019-05-21 10:33:50 +08:00
|
|
|
DEFAULTS(
|
2022-10-28 04:17:19 +08:00
|
|
|
NAMESERVER_TTL('24h'),
|
|
|
|
DefaultTTL('12h'),
|
|
|
|
CF_PROXY_DEFAULT_OFF
|
2019-05-21 10:33:50 +08:00
|
|
|
);
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2022-09-30 03:10:31 +08:00
|
|
|
# Advanced Examples
|
|
|
|
|
|
|
|
## Automate Fastmail DKIM records
|
|
|
|
|
|
|
|
In this example we need a macro that can dynamically change for each domain.
|
|
|
|
|
|
|
|
Suppose you have many domains that use Fastmail as an MX. Here's a macro that sets the MX records.
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2022-09-30 03:10:31 +08:00
|
|
|
var FASTMAIL_MX = [
|
|
|
|
MX('@', 10, 'in1-smtp.messagingengine.com.'),
|
|
|
|
MX('@', 20, 'in2-smtp.messagingengine.com.'),
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
Fastmail also supplied CNAMES to implement DKIM, and they all match a pattern
|
|
|
|
that includes the domain name. We can't use a simple macro. Instead, we use
|
|
|
|
a function that takes the domain name as a parameter to generate the right
|
|
|
|
records dynamically.
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2022-09-30 03:10:31 +08:00
|
|
|
var FASTMAIL_DKIM = function(the_domain){
|
|
|
|
return [
|
|
|
|
CNAME('fm1._domainkey', 'fm1.' + the_domain + '.dkim.fmhosted.com.'),
|
|
|
|
CNAME('fm2._domainkey', 'fm2.' + the_domain + '.dkim.fmhosted.com.'),
|
|
|
|
CNAME('fm3._domainkey', 'fm3.' + the_domain + '.dkim.fmhosted.com.')
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
We can then use the macros as such:
|
|
|
|
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2022-09-30 03:10:31 +08:00
|
|
|
D("example.com", REG_NONE, DnsProvider(DSP_R53_MAIN),
|
|
|
|
FASTMAIL_MX,
|
|
|
|
FASTMAIL_DKIM('example.com')
|
|
|
|
)
|
|
|
|
```
|