$ORIGIN, @ and blank Substitution
From: https://www.zytrax.com/books/dns/apa/origin.html
$ORIGIN, @ and blank Substitution
The symbol @ is used in BIND to denote zone root (which is sometimes also
called the zone apex. The value substituted for @ is either:
- The last $ORIGIN directive encountered in the file. To illustrate possible
uses:
; example.com zone file fragment
$ORIGIN example.com.
@ IN SOA ns1.example.com. hostmaster.example.com. (
2003080800 ; se = serial number
172800 ; ref = refresh = 2d
900 ; ret = update retry = 15m
1209600 ; ex = expiry = 2w
3600 ; min = minimum = 1h
)
....
@ IN NS ns1.example.com.
; ns1.example.com. is the NS for example.com
; and could have written as
example.com. IN NS ns1.example.com.
; OR using blank substitution
IN NS ns1.example.com.
; MX traditionally written using blank substitution
IN MX 10 mail.example.com.
; but could have been written as
@ IN MX 10 mail.example.com.
...
; @ works anywhere
www IN A 192.168.2.3
; this RR allows use of http://example.com
@ IN A 192.168.2.3
; and could have been written as
example.com. IN A 192.168.2.3
...
$ORIGIN uk.example.com.
; @ reference last $ORIGIN
@ IN NS ns2.example.com.
; ns2.example.com. is name server for uk.example.com subdomain
; and could have been written as
uk.example.com. IN NS ns2.example.com.
- If no $ORIGIN directive is present - BIND synthesizes one from the value of
the zone name in the named.conf file , for example:
// named.conf file fragment
zone "example.com" in{
type master;
file "pri.example.com";
};
example.com. is synthesized as the zone $ORIGIN and will replace @ in the
zone file.
; example.com zone file fragment
; no ORIGIN directive
@ IN SOA ns1.example.com. hostmaster.example.com. (
2003080800 ; se = serial number
172800 ; ref = refresh = 2d
900 ; ret = update retry = 15m
1209600 ; ex = expiry = 2w
3600 ; min = minimum = 1h
)
....
@ IN NS ns1.example.com.
; ns1.example.com. is the NS for example.com
; and could have written as
example.com. IN NS ns1.example.com.
; OR using blank substitution
IN NS ns1.example.com.
....
Blank Substitution
Blank labels are a little messy and the substitution here is the last valid
name (or label) or $ORIGIN if there are no previous names (labels). To
illustrate blank name substitution:
; example.com zone file fragment
; no ORIGIN directive
@ IN SOA ns1.example.com. hostmaster.example.com. (
2003080800 ; se = serial number
172800 ; ref = refresh = 2d
900 ; ret = update retry = 15m
1209600 ; ex = expiry = 2w
3600 ; min = minimum = 1h
)
....
IN NS ns1.example.com.
; the blank label in the NS substitutes example.com.
; Confusingly the whole definition could use blank substitution
; as shown below which is functionally equivalent to above
; example.com zone file fragment
; no ORIGIN directive
IN SOA ns1.example.com. hostmaster.example.com. (
2003080800 ; se = serial number
172800 ; ref = refresh = 2d
900 ; ret = update retry = 15m
1209600 ; ex = expiry = 2w
3600 ; min = minimum = 1h
)
....
IN NS ns1.example.com.
Finally, to illustrate other uses of blank substitution see the following:
; zone file fragment for example.com.
...
; following two A RRs both have a label of www.example.com.
www IN A 192.168.2.3
IN A 192.168.2.4
; this could have also been written as shown if less confusing
www IN A 192.168.2.3
www IN A 192.168.2.4