# traceroute — Trace the Network Path Hop by Hop

> Practical guide to traceroute and tracepath — trace network paths hop by hop, pinpoint latency spikes, and work around firewalls with alternative probes.

Source: https://www.jpkc.com/db/en/cheatsheets/networking/traceroute/

<!-- PROSE:intro -->
traceroute shows you the hop-by-hop path that packets take from your machine to a destination host – and pinpoints where latency or packet loss occurs along the way. It sends probes with incrementally increasing TTL values; each router that discards a packet replies with an ICMP message, revealing its address and round-trip time. This lets you tell at a glance whether a problem lies with your ISP, a transit router, or the destination server itself.
<!-- PROSE:intro:end -->

## Basic Usage

`traceroute HOST` — Trace the route to a host using UDP probes (default).

```bash
traceroute 8.8.8.8
```

`traceroute HOSTNAME` — Trace the route to a hostname with DNS resolution.

```bash
traceroute google.com
```

`traceroute -n HOST` — Numeric output only — skip reverse DNS lookups. Much faster.

```bash
traceroute -n 8.8.8.8
```

`traceroute -q N HOST` — Set the number of probe packets per hop (default: 3).

```bash
traceroute -q 1 8.8.8.8
```

`traceroute -w TIMEOUT HOST` — Set the timeout in seconds to wait for a response (default: 5).

```bash
traceroute -w 3 8.8.8.8
```

`traceroute -m MAX_TTL HOST` — Set the maximum number of hops (default: 30).

```bash
traceroute -m 20 8.8.8.8
```

`traceroute -f FIRST_TTL HOST` — Start with a specific TTL value instead of 1.

```bash
traceroute -f 5 8.8.8.8
```

## Probe Methods

`traceroute -I HOST` — Use ICMP Echo probes instead of UDP. Often gives better results through firewalls.

```bash
sudo traceroute -I 8.8.8.8
```

`traceroute -T HOST` — Use TCP SYN probes. Good for tracing through firewalls that block UDP/ICMP.

```bash
sudo traceroute -T 8.8.8.8
```

`traceroute -T -p PORT HOST` — Use TCP SYN probes on a specific port.

```bash
sudo traceroute -T -p 443 8.8.8.8
```

`traceroute -U HOST` — Use UDP probes (default method).

```bash
traceroute -U 8.8.8.8
```

`traceroute -p PORT HOST` — Set the destination port for UDP probes (default: 33434).

```bash
traceroute -p 53 8.8.8.8
```

## Advanced Options

`traceroute -s SOURCE HOST` — Set the source IP address for outgoing probes.

```bash
traceroute -s 10.0.0.5 8.8.8.8
```

`traceroute -i INTERFACE HOST` — Use a specific network interface.

```bash
traceroute -i eth0 8.8.8.8
```

`traceroute -z PAUSE HOST` — Set the pause between probes in milliseconds.

```bash
traceroute -z 50 8.8.8.8
```

`traceroute -A HOST` — Show AS (Autonomous System) numbers at each hop.

```bash
traceroute -A 8.8.8.8
```

`traceroute -e HOST` — Show ICMP extensions (MPLS labels, etc.).

```bash
traceroute -e 8.8.8.8
```

`traceroute -6 HOST` — Force IPv6 traceroute.

```bash
traceroute -6 google.com
```

`traceroute6 HOST` — IPv6 traceroute command (alias on many systems).

```bash
traceroute6 google.com
```

## tracepath (No Root Required)

`tracepath HOST` — Trace path to host and discover Path MTU. No root required.

```bash
tracepath 8.8.8.8
```

`tracepath -n HOST` — Numeric output only — skip DNS resolution.

```bash
tracepath -n 8.8.8.8
```

`tracepath -b HOST` — Show both hostname and IP address.

```bash
tracepath -b 8.8.8.8
```

`tracepath -m MAX_HOPS HOST` — Set maximum hop count (default: 30).

```bash
tracepath -m 20 8.8.8.8
```

`tracepath -l PACKET_LEN HOST` — Set the initial packet length for MTU discovery.

```bash
tracepath -l 1500 8.8.8.8
```

`tracepath -p PORT HOST` — Set the destination port.

```bash
tracepath -p 443 8.8.8.8
```

`tracepath -4 HOST` — Force IPv4.

```bash
tracepath -4 google.com
```

`tracepath -6 HOST` — Force IPv6.

```bash
tracepath -6 google.com
```

## Reading the Output

` 1  192.168.1.1  1.234 ms  0.987 ms  1.102 ms` — Normal hop: hop number, router IP, and three round-trip times.

` 5  * * *` — No response from this hop. The router may block ICMP/UDP or has no reverse route.

` 3  10.0.0.1  2.5 ms !N  * *` — !N = Network unreachable. Other codes: !H (host), !P (protocol), !F (fragmentation needed).

`Resume: pmtu 1500` — tracepath output: the discovered Path MTU to the destination.

## Common Patterns

`traceroute -n -q 1 -w 2 HOST` — Fast traceroute: no DNS, one probe per hop, 2 second timeout.

```bash
traceroute -n -q 1 -w 2 8.8.8.8
```

`sudo traceroute -I -n HOST` — ICMP traceroute without DNS — most reliable through firewalls.

```bash
sudo traceroute -I -n 8.8.8.8
```

`sudo traceroute -T -p 443 -n HOST` — TCP traceroute on HTTPS port — works through most firewalls.

```bash
sudo traceroute -T -p 443 -n 8.8.8.8
```

`traceroute HOST | awk '{print $1, $2}'` — Extract hop numbers and IPs only.

```bash
traceroute -n 8.8.8.8 | awk '{print $1, $2}'
```

<!-- PROSE:outro -->
## Conclusion

For most connectivity problems, `traceroute -n` is the first tool to reach for – you see instantly where the path ends or where latency spikes. If firewalls block UDP probes, switch to `-I` (ICMP) or `-T -p 443` (TCP). For continuous monitoring, `mtr` supersedes traceroute as a more informative alternative.

## Further Reading

- [Traceroute – Wikipedia](https://en.wikipedia.org/wiki/Traceroute) – background and how it works
- [traceroute(8) – manual page](https://linux.die.net/man/8/traceroute) – every option at a glance
<!-- PROSE:outro:end -->

## Related Commands

- [mtr](https://www.jpkc.com/db/en/cheatsheets/networking/mtr/) – combines traceroute and ping for continuous network monitoring
- [ping](https://www.jpkc.com/db/en/cheatsheets/networking/ping/) – check host reachability and measure round-trip time
- [dig](https://www.jpkc.com/db/en/cheatsheets/networking/dig/) – verify DNS resolution when hostnames don't resolve correctly

