traceroute - macOS


Overview

The traceroute command traces the route taken by packets from the local host to a specified destination. It sends packets with progressively increasing Time to Live (TTL) values and prints the addresses of the routers that return ICMP Time Exceeded messages. This helps identify the path taken by network traffic and troubleshoot network connectivity issues.

Syntax

traceroute [options] destination

Options/Flags

| Option | Description |
|—|—|
| -n | Disable name resolution for IP addresses. |
| -s source-ip | Set the source IP address for tracing. |
| -d | Set the Don’t Fragment (DF) bit in the IP header. |
| -t protocol | Specify the protocol to use for tracing (udp, tcp, icmp). |
| -p port | Specify the port to use for tracing (UDP or TCP). |
| -P | Disable ICMP port/protocol unreachable messages. |
| -I interface | Specify the interface to use for sending packets. |
| -m ttl | Set the maximum TTL to use for tracing. |
| -f first-ttl | Set the first TTL to use for tracing. |
| -T | Trace only the first hop. |
| -L | Trace only the last hop. |
| -v | Increase verbosity (multiple times for more verbosity). |
| -h | Display help and usage information. |

Examples

  • Trace the route to google.com:
traceroute google.com
  • Trace with DNS resolution disabled:
traceroute -n google.com
  • Trace using port 8080:
traceroute -p 8080 google.com
  • Trace the maximum of 30 hops:
traceroute -m 30 google.com

Common Issues

  • “Could not resolve host” error: Ensure that DNS resolution is enabled (-n) or that the IP address is specified directly.
  • “Permission denied” error: Ensure that the user has permission to send packets from the specified interface (-I).
  • No response from hops: Consider increasing the maximum TTL (-m) or using another protocol (-t).
  • Incomplete trace: Some routers may not respond to ICMP Time Exceeded messages.
  • Slow trace: Tracing can be slow, especially over long distances or congested networks.

Integration

  • Use with ping: Combine traceroute with ping to test network latency and connectivity.
  • Scripts: Create scripts to automate tracing tasks, such as monitoring network connectivity or troubleshooting specific issues.
  • macOS Network Utility: The macOS Network Utility app includes a graphical interface for traceroute.