How to use the command 'tcptraceroute' (with examples)
- Linux
- December 25, 2023
The ’tcptraceroute’ command is a traceroute implementation that uses TCP packets instead of ICMP packets. It allows you to trace the route to a host by sending TCP packets with varying TTL values and analyzing the responses received. This can be useful for diagnosing network issues, identifying the number of hops between your computer and a destination host, and identifying any potential bottlenecks in the network.
Use case 1: Trace the route to a host
Code:
tcptraceroute host
Motivation: This use case allows you to trace the route to a specific host by providing its domain name or IP address as the argument to the ’tcptraceroute’ command. It can help you understand the path that network packets take to reach the destination host and identify any latency or connectivity issues along the way.
Explanation:
host
: Specifies the destination host. It can be a domain name or an IP address.
Example output:
traceroute to example.com (93.184.216.34), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 2.245 ms 2.343 ms 2.487 ms
2 10.0.0.1 (10.0.0.1) 3.245 ms 3.187 ms 3.325 ms
3 74.125.64.1 (74.125.64.1) 5.128 ms 5.267 ms 5.182 ms
4 108.134.1.142 (108.134.1.142) 6.496 ms 6.478 ms 6.719 ms
5 173.178.37.58 (173.178.37.58) 7.831 ms 7.700 ms 7.782 ms
...
Use case 2: Specify the destination port and packet length in bytes
Code:
tcptraceroute host destination_port packet_length
Motivation: By specifying the destination port, you can trace the route to a specific port on the destination host. Additionally, specifying the packet length allows you to customize the size of the TCP packets sent during the traceroute process.
Explanation:
host
: Specifies the destination host. It can be a domain name or an IP address.destination_port
: Specifies the destination port number.packet_length
: Specifies the length of the TCP packets in bytes.
Example output:
traceroute to example.com (93.184.216.34), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 2.245 ms 2.343 ms 2.487 ms
2 10.0.0.1 (10.0.0.1) 3.245 ms 3.187 ms 3.325 ms
3 74.125.64.1 (74.125.64.1) 5.128 ms 5.267 ms 5.182 ms
4 108.134.1.142 (108.134.1.142) 6.496 ms 6.478 ms 6.719 ms
5 173.178.37.58 (173.178.37.58) 7.831 ms 7.700 ms 7.782 ms
...
Use case 3: Specify the local source port and source address
Code:
tcptraceroute host -p source_port -s source_address
Motivation: By specifying the local source port and source address, you can control the source of the TCP packets sent during the traceroute process. This can be useful in situations where you want to test connectivity from a specific source IP address or through a specific firewall rule.
Explanation:
host
: Specifies the destination host. It can be a domain name or an IP address.-p source_port
: Specifies the local source port number.-s source_address
: Specifies the local source IP address.
Example output:
traceroute to example.com (93.184.216.34), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 2.245 ms 2.343 ms 2.487 ms
2 10.0.0.1 (10.0.0.1) 3.245 ms 3.187 ms 3.325 ms
3 74.125.64.1 (74.125.64.1) 5.128 ms 5.267 ms 5.182 ms
4 108.134.1.142 (108.134.1.142) 6.496 ms 6.478 ms 6.719 ms
5 173.178.37.58 (173.178.37.58) 7.831 ms 7.700 ms 7.782 ms
...
Use case 4: Set the first and maximum TTL
Code:
tcptraceroute host -f first_ttl -m max_ttl
Motivation: This use case allows you to customize the initial Time to Live (TTL) value and the maximum TTL value used during the traceroute process. The TTL value determines the number of hops that a packet can traverse before being discarded. By setting these values, you can customize the scope of the traceroute process.
Explanation:
host
: Specifies the destination host. It can be a domain name or an IP address.-f first_ttl
: Specifies the initial TTL value.-m max_ttl
: Specifies the maximum TTL value.
Example output:
traceroute to example.com (93.184.216.34), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 2.245 ms 2.343 ms 2.487 ms
2 10.0.0.1 (10.0.0.1) 3.245 ms 3.187 ms 3.325 ms
3 74.125.64.1 (74.125.64.1) 5.128 ms 5.267 ms 5.182 ms
4 108.134.1.142 (108.134.1.142) 6.496 ms 6.478 ms 6.719 ms
5 173.178.37.58 (173.178.37.58) 7.831 ms 7.700 ms 7.782 ms
...
Use case 5: Specify the wait time and number of queries per hop
Code:
tcptraceroute host -w wait_time -q number_of_queries
Motivation: By specifying the wait time and number of queries per hop, you can control how long ’tcptraceroute’ waits for a response from each hop and the number of queries sent per hop. This can be useful for adjusting the timeout and query rate based on network conditions or performance requirements.
Explanation:
host
: Specifies the destination host. It can be a domain name or an IP address.-w wait_time
: Specifies the time to wait for response in milliseconds.-q number_of_queries
: Specifies the number of TCP packets to send per hop.
Example output:
traceroute to example.com (93.184.216.34), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 2.245 ms 2.343 ms 2.487 ms
2 10.0.0.1 (10.0.0.1) 3.245 ms 3.187 ms 3.325 ms
3 74.125.64.1 (74.125.64.1) 5.128 ms 5.267 ms 5.182 ms
4 108.134.1.142 (108.134.1.142) 6.496 ms 6.478 ms 6.719 ms
5 173.178.37.58 (173.178.37.58) 7.831 ms