How to use the command tracepath (with examples)
- Linux
- December 25, 2023
Tracepath is a command-line utility that allows users to trace the path to a network host, discovering the Maximum Transmission Unit (MTU) along this path. It provides valuable information about the routing path and the network congestion users may experience while reaching a specific host. This article will illustrate each of the following use cases of the tracepath command.
Use case 1: A preferred way to trace the path to a host
Code:
tracepath -p 33434 host
Motivation:
Tracing the path to a host using the tracepath command is a common scenario for network troubleshooting. By including the -p
option followed by a destination port number, users have the flexibility to specify the initial destination port.
Explanation:
-p
: Specifies the initial destination port.33434
: The port number to be used for the tracepath command.host
: The hostname or IP address of the target host.
Example output:
1: router1 (192.168.1.1) 0.100ms pmtu 1500
1: router1 (192.168.1.1) 0.065ms
2: router2 (10.0.0.2) 0.098ms
3: router3 (172.16.0.1) 0.123ms
...
30: host (10.10.10.10) 0.456ms reached
Use case 2: Specify the initial destination port
Code:
tracepath -p destination_port host
Motivation:
Sometimes, network environments have non-standard firewall settings that require the use of a specific destination port. The -p
option allows users to specify the initial destination port, ensuring the tracepath command operates correctly within such environments.
Explanation:
-p
: Specifies the initial destination port.destination_port
: The specific destination port number required by the firewall settings.host
: The hostname or IP address of the target host.
Example output:
1: router1 (192.168.1.1) 0.100ms pmtu 1500
1: router1 (192.168.1.1) 0.065ms
2: router2 (10.0.0.2) 0.098ms
3: router3 (172.16.0.1) 0.123ms
...
30: host (10.10.10.10) 0.456ms reached
Use case 3: Print both hostnames and numerical IP addresses
Code:
tracepath -b host
Motivation:
In certain scenarios, it is necessary to view both the hostnames and the numerical IP addresses for the network devices in the tracepath. The -b
option allows users to print both of these details, providing a comprehensive view of the network route.
Explanation:
-b
: Prints both hostnames and numerical IP addresses.host
: The hostname or IP address of the target host.
Example output:
1: router1 (192.168.1.1) 0.100ms pmtu 1500
1: 192.168.1.1 0.065ms
2: router2 (10.0.0.2) 0.098ms
3: router3 (172.16.0.1) 0.123ms
...
30: host (10.10.10.10) 0.456ms reached
Use case 4: Specify a maximum TTL (number of hops)
Code:
tracepath -m max_hops host
Motivation:
Limiting the number of hops while tracing the path to a host can be useful, especially when troubleshooting network connectivity issues. The -m
option allows users to specify the maximum Time To Live (TTL), which effectively limits the number of hops made.
Explanation:
-m
: Specifies the maximum TTL (number of hops).max_hops
: The maximum number of hops before the tracepath command terminates.host
: The hostname or IP address of the target host.
Example output:
1: router1 (192.168.1.1) 0.100ms pmtu 1500
1: router1 (192.168.1.1) 0.065ms
2: router2 (10.0.0.2) 0.098ms
3: router3 (172.16.0.1) 0.123ms
...
10: host (10.10.10.10) 0.456ms reached
Use case 5: Specify the initial packet length for IPv4 or IPv6
Code:
tracepath -l packet_length host
Motivation:
The initial packet length can have an impact on network performance, especially when dealing with different IP versions. The -l
option allows users to specify the initial packet length, giving them control over the performance of the tracepath command.
Explanation:
-l
: Specifies the initial packet length.packet_length
: The desired packet length for the tracepath command.host
: The hostname or IP address of the target host.
Example output:
1: router1 (192.168.1.1) 0.100ms pmtu 1500
1: router1 (192.168.1.1) 0.065ms
2: router2 (10.0.0.2) 0.098ms
3: router3 (172.16.0.1) 0.123ms
...
30: host (10.10.10.10) 0.456ms reached
Use case 6: Use only IPv6 addresses
Code:
tracepath -6 host
Motivation:
In some situations, users may want to exclusively use IPv6 addresses when tracing the path to a host. The -6
option allows users to instruct the tracepath command to only use IPv6 addresses for the tracepath operation.
Explanation:
-6
: Forces the tracepath command to use IPv6 addresses only.host
: The hostname or IP address of the target host.
Example output:
1: router1 (2001:db8:0:1::1) 0.100ms pmtu 1500
1: router1 (2001:db8:0:1::1) 0.065ms
2: router2 (2001:db8:0:2::2) 0.098ms
3: router3 (2001:db8:0:3::1) 0.123ms
...
30: host (2001:db8:0:10::10) 0.456ms reached
Conclusion
The tracepath command provides a comprehensive way to trace the path to a network host and discover the MTU along the way. By understanding the various use cases and options available, users can effectively troubleshoot network connectivity issues and gain valuable insights into their network infrastructure.