github.com/StackExchange/dnscontrol/v4@v4.11.0/documentation/language-reference/domain-modifiers/PTR.md (about)

     1  ---
     2  name: PTR
     3  parameters:
     4    - name
     5    - target
     6    - modifiers...
     7  parameter_types:
     8    name: string
     9    target: string
    10    "modifiers...": RecordModifier[]
    11  ---
    12  
    13  PTR adds a PTR record to the domain.
    14  
    15  The name is normally a relative label for the domain, or a FQDN that ends with `.`.  If magic mode is enabled (see below) it can also be an IP address, which will be replaced by the proper string automatically, thus
    16  saving the user from having to reverse the IP address manually.
    17  
    18  Target should be a string representing the FQDN of a host.  Like all FQDNs in DNSControl, it must end with a `.`.
    19  
    20  # Magic Mode
    21  
    22  PTR records are complex and typos are common. Therefore DNSControl
    23  enables features to save labor and
    24  prevent typos.  This magic is only
    25  enabled when the domain ends with `in-addr.arpa.` or `ipv6.arpa.`.
    26  
    27  *Automatic IP-to-reverse:* If the name is a valid IP address, DNSControl will replace it with
    28  a string that is appropriate for the domain. That is, if the domain
    29  ends with `in-addr.arpa` (no `.`) and name is a valid IPv4 address, the name
    30  will be replaced with the correct string to make a reverse lookup for that address.
    31  IPv6 is properly handled too.
    32  
    33  *Extra Validation:* DNSControl considers it an error to include a name that
    34  is inappropriate for the domain.  For example
    35  `PTR("1.2.3.4", "f.co.")` is valid for the domain `D("3.2.1.in-addr.arpa",`
    36   but DNSControl will generate an error if the domain is `D("9.9.9.in-addr.arpa",`.
    37  This is because `1.2.3.4` is contained in `1.2.3.0/24` but not `9.9.9.0/24`.
    38  This validation works for IPv6, IPv4, and
    39  RFC2317 "Classless in-addr.arpa delegation" domains.
    40  
    41  *Automatic truncation:* DNSControl will automatically truncate FQDNs
    42  as needed.
    43  If the name is a FQDN ending with `.`, DNSControl will verify that the
    44  name is contained within the CIDR block implied by domain.  For example
    45  if name is `4.3.2.1.in-addr.arpa.` (note the trailing `.`)
    46  and the domain is `2.1.in-addr.arpa` (no trailing `.`)
    47  then the name will be replaced with `4.3`.  Note that the output
    48  of `REV("1.2.3.4")` is `4.3.2.1.in-addr.arpa.`, which means the following
    49  are all equivalent:
    50  
    51  * `PTR(REV("1.2.3.4", ...`
    52  * `PTR("4.3.2.1.in-addr.arpa.", ...`
    53  * `PTR("4.3", ...`    // Assuming the domain is `2.1.in-addr.arpa`
    54  
    55  All magic is RFC2317-aware. We use the first format listed in the
    56  RFC for both [`REV()`](../top-level-functions/REV.md) and `PTR()`. The format is
    57  `FIRST/MASK.C.B.A.in-addr.arpa` where `FIRST` is the first IP address
    58  of the zone, `MASK` is the netmask of the zone (25-31 inclusive),
    59  and A, B, C are the first 3 octets of the IP address. For example
    60  `172.20.18.130/27` is located in a zone named
    61  `128/27.18.20.172.in-addr.arpa`
    62  
    63  {% code title="dnsconfig.js" %}
    64  ```javascript
    65  D(REV("1.2.3.0/24"), REGISTRAR, DnsProvider(BIND),
    66    PTR("1", "foo.example.com."),
    67    PTR("2", "bar.example.com."),
    68    PTR("3", "baz.example.com."),
    69    // If the first parameter is a valid IP address, DNSControl will generate the correct name:
    70    PTR("1.2.3.10", "ten.example.com."),    // "10"
    71  END);
    72  ```
    73  {% endcode %}
    74  
    75  {% code title="dnsconfig.js" %}
    76  ```javascript
    77  D(REV("9.9.9.128/25"), REGISTRAR, DnsProvider(BIND),
    78    PTR("9.9.9.129", "first.example.com."),
    79  END);
    80  ```
    81  {% endcode %}
    82  
    83  {% code title="dnsconfig.js" %}
    84  ```javascript
    85  D(REV("2001:db8:302::/48"), REGISTRAR, DnsProvider(BIND),
    86    PTR("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", "foo.example.com."),  // 2001:db8:302::1
    87    // If the first parameter is a valid IP address, DNSControl will generate the correct name:
    88    PTR("2001:db8:302::2", "two.example.com."),                          // "2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0"
    89    PTR("2001:db8:302::3", "three.example.com."),                        // "3.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0"
    90  END);
    91  ```
    92  {% endcode %}
    93  
    94  # Automatic forward and reverse lookups
    95  
    96  DNSControl does not automatically generate forward and reverse lookups. However
    97  it is possible to write a macro that does this by using the 
    98  [`D_EXTEND()`](../global/D_EXTEND.md)
    99  function to insert `A` and `PTR` records into previously-defined domains.
   100  
   101  {% code title="dnsconfig.js" %}
   102  ```javascript
   103  function FORWARD_AND_REVERSE(ipaddr, fqdn) {
   104      D_EXTEND(dom,
   105          A(fqdn, ipaddr)
   106      );
   107      D_EXTEND(REV(ipaddr),
   108          PTR(ipaddr, fqdn)
   109      );
   110  }
   111  
   112  D("example.com", REGISTRAR, DnsProvider(DSP_NONE),
   113      ...,
   114  END);
   115  D(REV("10.20.30.0/24"), REGISTRAR, DnsProvider(DSP_NONE),
   116      ...,
   117  END);
   118  
   119  FORWARD_AND_REVERSE("10.20.30.77", "foo.example.com.");
   120  FORWARD_AND_REVERSE("10.20.30.99", "bar.example.com.");
   121  ```
   122  {% endcode %}