Cos'è TTL?
TTL (Time To Live) è un'impostazione DNS che specifica, in pochi secondi, quanto tempo dovrebbe essere memorizzato un record DNS da risolutori, browser e altri sistemi prima di richiedere una copia nuova da server di nome autorevoli. I valori TTL si bilanciano tra la propagazione rapida dei cambiamenti DNS (basso TTL) e il carico del server ridotto con prestazioni migliori (alto TTL).Come funziona TTL
DNS Query Flow with TTL:
1. Client queries resolver for example.com
2. Resolver checks cache - not found
3. Resolver queries authoritative server
4. Server returns: A record 192.0.2.1, TTL 3600
5. Resolver caches for 3600 seconds (1 hour)
6. Subsequent queries served from cache
7. After 3600s, cache expires, cycle repeats
Valori TTL comuni
| TTL (secondi) | Durata | Utilizzare il caso |
|---|---|---|
| 60-300 | 1-5 minuti | Durante le modifiche DNS, failover |
| 300-900 | 5-15 minuti | Servizi dinamica |
| 3600 | 1 ora | Siti web standard |
| 14400 | 4 ore | Record stabile |
| 86. | 24 ore su 24 | Raramente cambiando record |
TTL in DNS Records
Formato record
example.com. 3600 IN A 192.0.2.1
│
└── TTL in seconds
Different TTLs per Record
; Stable nameservers - high TTL
example.com. 86400 IN NS ns1.example.com.
; Web server - moderate TTL
www.example.com. 3600 IN A 192.0.2.1
; Dynamic content - low TTL
api.example.com. 300 IN A 192.0.2.50
Strategia TTL
Prima delle modifiche DNS
Più basso TTL prima dei cambiamenti previsti:
Timeline:
Day -2: Lower TTL from 86400 to 300
Day 0: Make DNS change
Day 0+: Change propagates within 5 minutes
Day +1: Raise TTL back to 86400
Tradeoffs
| Basso TTL (60-300) | Alto TTL (3600+) |
|---|---|
| Rapida propagazione | Propagazione lenta |
| Altre domande DNS | Domande DNS minori |
| Carico server più alto | Carico server inferiore |
| Meglio per il failover | Meglio per la stabilità |
| Latenza superiore | Latenza inferiore |
Propagazione TTL e DNS
TTL colpisce direttamente il tempo di propagazione:
Max propagation time ≈ Highest cached TTL
If TTL = 86400 (24 hours):
- Some users see old IP for up to 24 hours
- Global propagation: up to 24-48 hours
If TTL = 300 (5 minutes):
- Most users see new IP within 5-10 minutes
- Global propagation: under 1 hour
Corrente di controllo TTL
Using dig
dig example.com A
;; ANSWER SECTION:
example.com. 3542 IN A 192.0.2.1
│
└── Remaining TTL (seconds until cache expires)
Using nslookup
nslookup -debug example.com
Migliori Pratiche
1. Utilizzare valori appropriati: Abbina TTL per registrare la volatilità
2. Torre prima delle modifiche Ridurre TTL 24-48 ore
3. Consider caching layer: CDN, i browser aggiungono ritardi
4. Carico di bilanciamento contro velocità Non impostare inutilmente basso
5. Monitor dopo i cambiamenti Verificare la propagazione completa
6. Norme del documento Stabilire politiche TTL
TTL è un concetto DNS fondamentale che influisce direttamente su quanto velocemente i cambiamenti DNS abbiano effetto su Internet e su quanto carichino i tuoi nameserver.