Cosa fa#
Mostra il percorso completo che i pacchetti compiono dalla macchina locale a un host remoto, stampando ogni router (hop) attraversato con il tempo di risposta. Sfrutta il meccanismo TTL — manda pacchetti con TTL incrementale (1, 2, 3...) e raccoglie i messaggi ICMP Time Exceeded che ogni router manda quando il TTL scade.
Sintassi#
traceroute [opzioni] host
Comandi essenziali#
| Comando | Flag | Significato flag | Cosa fa |
|---|---|---|---|
traceroute google.com | — | — | Traccia il percorso verso google.com |
traceroute -n google.com | -n | numeric | Non risolve i nomi DNS degli hop — piu' veloce |
traceroute -T google.com | -T | TCP | Usa TCP invece di UDP — supera alcuni firewall |
traceroute -I google.com | -I | ICMP | Usa ICMP — utile quando UDP e' bloccato |
traceroute -m 20 host | -m | max hops | Limita a 20 hop massimi |
traceroute -w 2 host | -w | wait | Attende max 2 secondi per ogni risposta |
Leggere l'output#
traceroute target.com
# 1 192.168.1.254 (192.168.1.254) 5.9 ms 4.9 ms 4.6 ms
# 2 192.168.128.1 (192.168.128.1) 8.2 ms 7.7 ms 7.3 ms
# 3 * * *
# 4 172.30.25.193 28.0 ms 33.5 ms 19.9 ms
# 5 backbone.isp.it 22.3 ms 31.8 ms 19.9 ms
# 6 cloudflare-peering.it 42.0 ms 33.6 ms 39.5 ms
# 7 198.x.x.x 39.7 ms 29.7 ms 32.3 mshop n. hostname (IP) RTT1 RTT2 RTT3
^ ^ ^
| | tre misurazioni per hop
| * * * = router che non risponde agli ICMP
numero router attraversato* * * — router che ignora i messaggi ICMP. Non significa che non esiste — solo che e' configurato per non rispondere. Normale su router ISP. Aggiunge -T o -I per aggirarlo.
I tre tempi — ogni hop viene misurato tre volte. Valori molto diversi tra loro indicano congestione o routing asimmetrico.
Come funziona internamente#
PASSO 1 — pacchetto con TTL=1
[Tu] ──TTL=1──► [Router 1]
TTL=0 → scarta
invia ICMP Time Exceeded
traceroute annota: hop 1 = IP di Router 1
PASSO 2 — pacchetto con TTL=2
[Tu] ──TTL=2──► [Router 1] ──TTL=1──► [Router 2]
TTL=0 → scarta
invia ICMP Time Exceeded
traceroute annota: hop 2 = IP di Router 2
... e cosi' via fino alla destinazioneVedi routing-hop-ttl per il concetto completo di TTL e hop.
Scenario Reale#
# Diagnosi: server non raggiungibile
traceroute -n 198.x.x.x
# Output:
# 1 192.168.1.1 2ms ← router di casa OK
# 2 10.0.0.1 8ms ← ISP OK
# 3 * * * ← router ISP che non risponde (normale)
# 4 85.x.x.x 15ms ← backbone ISP OK
# 5 * * * ← silenzio
# 6 * * * ← silenzio — il pacchetto si perde quiIl problema e' all'hop 5-6 — non dal lato tuo. Informazione da dare all'ISP o all'hosting provider. Senza traceroute avresti solo "non risponde" senza sapere dove si rompe il percorso.
# Supera i firewall che bloccano UDP (default di traceroute)
traceroute -T google.com # usa TCP porta 80
traceroute -I google.com # usa ICMP come pingDove l'ho usato#
- Cap 16 TLCL — networking base
- routing-hop-ttl — concetto di TTL e hop
Note personali#
traceroute -n e' quasi sempre preferibile — salta la risoluzione DNS di ogni hop e completa molto piu' velocemente. Aggiungi i nomi solo se ti servono per identificare i provider.
Su macOS il comando si chiama traceroute ma usa ICMP di default invece di UDP. Su Linux usa UDP di default — aggiungi -I per comportamento simile a macOS.
## Collegato a
- system — categoria
- [ping](/comandi/ping/) — usa ICMP, misura latenza verso un singolo host
- [routing-hop-ttl](/concetti/routing-hop-ttl/) — concetto teorico di TTL e routing
- [ip](/comandi/ip/) — mostra la tabella di routing locale

