Cheatsheet & Examples: traceroute
Traceroute is a network diagnostic tool used to trace the path packets take from a source to a destination IP address or hostname. It displays the sequence of routers (hops) traversed, along with the round-trip time (RTT) for each hop. This information helps in identifying network bottlenecks or problems.
Basic Traceroute to a Host
Example Usage:
traceroute google.com
What it does: This will trace the route to google.com, displaying each hop's IP address and RTT. It uses UDP packets by default.
Command-line Arguments Explained:
- hostname: The hostname or IP address to which you want to trace the route.
Specifying the Number of Hops
Example Usage:
traceroute -m 20 google.com
What it does: This traces the route to google.com but limits the maximum number of hops to 20. This can be useful if you suspect a routing loop or to speed up the trace.
Command-line Arguments Explained:
- -m: Specifies the maximum TTL (Time To Live) value, which determines the maximum number of hops.
- 20: Sets the maximum TTL to 20.
- hostname: The hostname or IP address to which you want to trace the route.
Specifying the Probe Size
Example Usage:
traceroute -s 64 google.com
What it does: This sets the probe size to 64 bytes. This might be necessary to work around firewalls or other network devices that filter based on packet size.
Command-line Arguments Explained:
- -s: Specifies the packet size (in bytes) to use for the probes.
- 64: Sets the packet size to 64 bytes.
- hostname: The hostname or IP address to which you want to trace the route.
Using ICMP instead of UDP
Example Usage:
traceroute -I google.com
What it does: This forces traceroute to use ICMP echo requests (like ping) instead of the default UDP packets. This can be useful if UDP traffic is blocked.
Command-line Arguments Explained:
- -I: Uses ICMP echo requests.
- hostname: The hostname or IP address to which you want to trace the route.
Setting the Port Number
Example Usage:
traceroute -p 80 google.com
What it does: This specifies the destination port number for UDP probes. By default, traceroute uses a range of ports. Specifying a port number might be helpful in troubleshooting issues related to a specific application that uses that port.
Command-line Arguments Explained:
- -p: Specifies the destination port number.
- 80: Sets the destination port to 80 (HTTP).
- hostname: The hostname or IP address to which you want to trace the route.
Setting the Source Address
Example Usage:
traceroute -S 192.168.1.100 google.com
What it does: This sets the source IP address for the traceroute probes. This can be helpful if you have multiple network interfaces or if you need to simulate traffic from a specific IP address. Note that you may need appropriate permissions and the IP address must be configured on your machine.
Command-line Arguments Explained:
- -S: Specifies the source IP address.
- 192.168.1.100: Sets the source IP address to 192.168.1.100.
- hostname: The hostname or IP address to which you want to trace the route.

