2020-08-04 21:43:02 +08:00
|
|
|
---
|
|
|
|
name: D_EXTEND
|
|
|
|
parameters:
|
|
|
|
- name
|
|
|
|
- modifiers...
|
2023-01-13 05:59:42 +08:00
|
|
|
parameter_types:
|
|
|
|
name: string
|
|
|
|
"modifiers...": DomainModifier[]
|
2020-08-04 21:43:02 +08:00
|
|
|
---
|
|
|
|
|
2020-10-08 02:27:33 +08:00
|
|
|
`D_EXTEND` adds records (and metadata) to a domain previously defined
|
2023-03-16 06:43:57 +08:00
|
|
|
by [`D()`](D.md). It can also be used to add subdomain records (and metadata)
|
2020-10-08 02:27:33 +08:00
|
|
|
to a previously defined domain.
|
|
|
|
|
|
|
|
The first argument is a domain name. If it exactly matches a
|
2023-03-16 06:43:57 +08:00
|
|
|
previously defined domain, `D_EXTEND()` behaves the same as [`D()`](D.md),
|
2020-10-08 02:27:33 +08:00
|
|
|
simply adding records as if they had been specified in the original
|
2023-03-16 06:43:57 +08:00
|
|
|
[`D()`](D.md).
|
2020-10-08 02:27:33 +08:00
|
|
|
|
|
|
|
If the domain name does not match an existing domain, but could be a
|
|
|
|
(non-delegated) subdomain of an existing domain, the new records (and
|
|
|
|
metadata) are added with the subdomain part appended to all record
|
|
|
|
names (labels), and targets (as appropriate). See the examples below.
|
|
|
|
|
|
|
|
Matching the domain name to previously-defined domains is done using a
|
|
|
|
`longest match` algorithm. If `domain.tld` and `sub.domain.tld` are
|
2023-03-16 06:43:57 +08:00
|
|
|
defined as separate domains via separate [`D()`](D.md) statements, then
|
2023-05-25 04:09:22 +08:00
|
|
|
`D_EXTEND("sub.sub.domain.tld", ...)` would match `sub.domain.tld`,
|
2020-10-08 02:27:33 +08:00
|
|
|
not `domain.tld`.
|
|
|
|
|
|
|
|
Some operators only act on an apex domain (e.g.
|
2023-03-16 06:43:57 +08:00
|
|
|
[`CF_REDIRECT`](../domain/CF_REDIRECT.md) and [`CF_TEMP_REDIRECT`](../domain/CF_TEMP_REDIRECT.md)). Using them
|
2020-10-08 02:27:33 +08:00
|
|
|
in a `D_EXTEND` subdomain may not be what you expect.
|
2020-08-04 21:43:02 +08:00
|
|
|
|
2023-03-14 04:30:21 +08:00
|
|
|
{% code title="dnsconfig.js" %}
|
2023-01-20 20:56:20 +08:00
|
|
|
```javascript
|
2023-05-25 04:09:22 +08:00
|
|
|
D("domain.tld", REG_MY_PROVIDER, DnsProvider(DNS),
|
2020-10-08 02:27:33 +08:00
|
|
|
A("@", "127.0.0.1"), // domain.tld
|
|
|
|
A("www", "127.0.0.2"), // www.domain.tld
|
|
|
|
CNAME("a", "b") // a.domain.tld -> b.domain.tld
|
|
|
|
);
|
|
|
|
D_EXTEND("domain.tld",
|
|
|
|
A("aaa", "127.0.0.3"), // aaa.domain.tld
|
|
|
|
CNAME("c", "d") // c.domain.tld -> d.domain.tld
|
|
|
|
);
|
|
|
|
D_EXTEND("sub.domain.tld",
|
|
|
|
A("bbb", "127.0.0.4"), // bbb.sub.domain.tld
|
|
|
|
A("ccc", "127.0.0.5"), // ccc.sub.domain.tld
|
|
|
|
CNAME("e", "f") // e.sub.domain.tld -> f.sub.domain.tld
|
|
|
|
);
|
|
|
|
D_EXTEND("sub.sub.domain.tld",
|
|
|
|
A("ddd", "127.0.0.6"), // ddd.sub.sub.domain.tld
|
|
|
|
CNAME("g", "h") // g.sub.sub.domain.tld -> h.sub.sub.domain.tld
|
|
|
|
);
|
|
|
|
D_EXTEND("sub.domain.tld",
|
|
|
|
A("@", "127.0.0.7"), // sub.domain.tld
|
|
|
|
CNAME("i", "j") // i.sub.domain.tld -> j.sub.domain.tld
|
|
|
|
);
|
2022-02-18 01:22:31 +08:00
|
|
|
```
|
2023-03-14 04:30:21 +08:00
|
|
|
{% endcode %}
|
2020-08-04 21:43:02 +08:00
|
|
|
|
2023-03-07 04:23:06 +08:00
|
|
|
This will end up in the following modifications: (This output assumes the `--full` flag)
|
2020-10-08 02:30:10 +08:00
|
|
|
|
2022-02-18 01:22:31 +08:00
|
|
|
```text
|
2020-08-04 21:43:02 +08:00
|
|
|
******************** Domain: domain.tld
|
2020-10-08 02:27:33 +08:00
|
|
|
----- Getting nameservers from: cloudflare
|
|
|
|
----- DNS Provider: cloudflare...7 corrections
|
|
|
|
#1: CREATE A aaa.domain.tld 127.0.0.3
|
|
|
|
#2: CREATE A bbb.sub.domain.tld 127.0.0.4
|
|
|
|
#3: CREATE A ccc.sub.domain.tld 127.0.0.5
|
|
|
|
#4: CREATE A ddd.sub.sub.domain.tld 127.0.0.6
|
|
|
|
#5: CREATE A sub.domain.tld 127.0.0.7
|
|
|
|
#6: CREATE A www.domain.tld 127.0.0.2
|
|
|
|
#7: CREATE A domain.tld 127.0.0.1
|
|
|
|
#8: CREATE CNAME a.domain.tld b.domain.tld.
|
|
|
|
#9: CREATE CNAME c.domain.tld d.domain.tld.
|
|
|
|
#10: CREATE CNAME e.sub.domain.tld f.sub.domain.tld.
|
|
|
|
#11: CREATE CNAME g.sub.sub.domain.tld h.sub.sub.domain.tld.
|
|
|
|
#12: CREATE CNAME i.sub.domain.tld j.sub.domain.tld.
|
2020-08-04 21:43:02 +08:00
|
|
|
```
|
2020-10-08 02:27:33 +08:00
|
|
|
|
|
|
|
ProTips: `D_EXTEND()` permits you to create very complex and
|
|
|
|
sophisticated configurations, but you shouldn't. Be nice to the next
|
|
|
|
person that edits the file, who may not be as expert as yourself.
|
|
|
|
Enhance readability by putting any `D_EXTEND()` statements immediately
|
2023-03-16 06:43:57 +08:00
|
|
|
after the original [`D()`](D.md), like in above example. Avoid the temptation
|
2020-10-08 02:27:33 +08:00
|
|
|
to obscure the addition of records to existing domains with randomly
|
|
|
|
placed `D_EXTEND()` statements. Don't build up a domain using loops of
|
|
|
|
`D_EXTEND()` statements. You'll be glad you didn't.
|