Welcome

Monday, May 2, 2011

Refresh DNS Cache Faster

For those manually configure the authoritative nameserver for a domain zone using BIND, modification has to be done in the zone file. For example, so domain zone example.com, you will see the following resource records in the zone file:



; zone 'example.com'
$TTL 14400

@ IN SOA ns1.example.com. host.example.com. (
2007080501 ; Serial
10800 ; Refresh 3 hours
3600 ; Retry 1 hour
604800 ; Expire 1 week
86400 ); Minimum 24 hours

@ NS ns1.example.com.
@ NS ns2.example.com.

@ A 192.168.0.1
@ MX 10 mail.example.com.

; nameservers
ns1 A 192.168.0.11
ns2 A 192.168.0.12
; mail servers
mail A 192.168.0.10
; web server
www CNAME example.com.
Now change the $TTL 14400 with the value you want (in seconds), such as 300 (5 minutes). This value defines the default TTL of all existing records, and by lowering this value to 300 (for example, you can choose your won value), caching server will be hold this records for more than 5 minutes before querying the authoritative name server which will be the first to reflect the new IP address when change later on again. Another value that you should change is minimum TTL, the last line of SOA type (remarked as minimum 24 hours).

After change, your DNS zone file will probably looks like this:

; zone 'example.com'
$TTL 300

@ IN SOA ns1.example.com. host.example.com. (
2007080501 ; Serial
10800 ; Refresh 3 hours
3600 ; Retry 1 hour
604800 ; Expire 1 week
300 ); Minimum 24 hours

@ NS ns1.example.com.
@ NS ns2.example.com.

@ A 192.168.0.1
@ MX 10 mail.example.com.

; nameservers
ns1 A 192.168.0.11
ns2 A 192.168.0.12
; mail servers
mail A 192.168.0.10
; web server
www CNAME example.com.
Restart the DNS service. The new TTL value will propagate to other DNS nameserver. This process typically takes 48 hours to 72 hours (hence the need to reduce TTL to try to make it faster when changing the critical A and MX records). After waiting for a few days, move your websites to new server or change the IP address, and then update the DNS records to point to the new server or IP.

Once done, you can now revert back the TTL values to reduce the load on your DNS server.

No comments: