The $TTL directive is defined in RFC 2308.
TTL in the DNS context defines the duration in seconds that the record may be cached. Zero indicates the record should not be cached. Note: RFC 1912 cautions that 0 = no caching is not widely implemented so make no assumptions.
The default TTL for the zone is defined in BIND9 by the $TTL directive which must appear at the beginning of the zone file i.e. before any RR to which it will apply. This $TTL is used for any Resource Record which does not explicitly set the 'ttl' field.
The TTL field is defined to be an unsigned 32 bit value with a valid range from 0 to 2147483647 (clarified in RFC 2181) - which is a long time! - somewhere on the other side of 68 years.
The $TTL field may take any time value.
In BIND 8 the SOA record (minimum parameter) was used to define the zone default TTL value. In BIND 9 the SOA 'minimum' parameter is used as the negative (NXDOMAIN) caching time (defined in RFC 2308).
RFC 1912 recommends that the $TTL value be set to 1 day or longer and that certain RRs which rarely change, such as the MX records for the domain, use an explicit TTL value to set even longer values such as 2 to 3 weeks. The value of this field is a balance between how frequently you think the DNS records will change vs load on the DNS server. In the example below the $TTL value of 2d (2 days) indicates that any change may not be fully propagated for 48 hours, equally caching DNS servers will require to re-read the RRs from your DNS every 48 hours which can be a non-trivial load. Many users will set this value to say 2w (2 weeks) in normal operation then prior to planned changes will reduce the value to say 1d or 12h, until the change has stabilized then restore the value to 2w.
Example
; example.com zone file fragment $TTL 2d ; zone default 3w IN MX 10 192.168.254.2 ; overrides default joe 3h IN A 192.168.254.3 ; overrides default www IN A 192.168.254.3 ; uses zone default = 2 days
BIND Time formats
BIND allows a number of time formats in combinations. Formats allowed are (case insensitive):
- #s = seconds = # x 1 seconds (really!)
- #m = minutes = # x 60 seconds
- #h = hours = # x 3600 seconds
- #d = day = # x 86400 seconds
- #w = week = # x 604800 seconds
Examples
; foo.com zone file fragment ; common origin (@) format @ IN SOA ns.foo.com. root.foo.com. ( 2003080800 ; serial number 10800s ; refresh = 3 hours 15M ; update retry = 15 minutes 3W12h ; expiry = 3 weeks + 12 hours 2h20M ; minimum = 2 hours + 20 minutes ) www 12H15m IN A 10.0.5.17 ; A record TTL value
REFERENCES
http://www.zytrax.com/books/dns/apa/ttl.html