How to Use traceroute Command in Linux: Syntax and Examples
Use the
traceroute command in Linux to trace the path packets take to reach a network host. Run traceroute [options] destination to see each hop between your computer and the target server.Syntax
The basic syntax of the traceroute command is:
traceroute [options] destination
Here, destination is the hostname or IP address you want to trace. Options modify how traceroute works, like setting the maximum number of hops or timeout.
bash
traceroute [options] destination
Example
This example shows how to trace the route to google.com. It lists each hop your packets take to reach Google's servers.
bash
traceroute google.com
Output
traceroute to google.com (142.250.190.78), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 1.123 ms 0.987 ms 1.045 ms
2 10.10.0.1 (10.10.0.1) 10.234 ms 10.456 ms 10.678 ms
3 203.0.113.1 (203.0.113.1) 20.345 ms 20.567 ms 20.789 ms
4 142.250.190.78 (142.250.190.78) 30.123 ms 30.456 ms 30.789 ms
Common Pitfalls
Some common mistakes when using traceroute include:
- Not running with sufficient permissions if required (some systems need
sudo). - Firewall or network devices blocking ICMP or UDP packets, causing incomplete results.
- Using incorrect destination names or IPs causing errors.
Always check your network settings and try with sudo if you get permission errors.
bash
traceroute example.com # If permission denied: sudo traceroute example.com
Quick Reference
| Option | Description |
|---|---|
| -m | Set max number of hops (time to live) |
| -w | Set time to wait for each reply (seconds) |
| -q | Number of probe packets per hop (default 3) |
| -I | Use ICMP ECHO instead of UDP packets |
| -n | Do not resolve IP addresses to hostnames |
Key Takeaways
Use
traceroute destination to see the path packets take to a host.Run with
sudo if you get permission errors.Options like
-m and -w control hops and timeouts.Firewalls may block traceroute packets, causing incomplete results.
Use
-n to speed up output by skipping DNS lookups.