Ubuntu traceroute Command Tutorial

Friday, Aug 9, 2024 | 4 minutes read | Update at Friday, Aug 9, 2024

@ İsmail Baydan

Ubuntu provides the traceroute command in order to check network path to the specified destination. The destination can be an IP address or hostname or an domain name. For example we can check the connectivity to the google.com with the traceroute command. Here are 20 examples of how to use the traceroute command on Ubuntu. Each example demonstrates a different option or feature that traceroute provides:

1. Basic traceroute Command

We can simply use the traceroute command by providing the destination hostname.

traceroute example.com

This command traces the route packets take to reach example.com.

2. Specify the Number of Queries per Hop

By default to show reliable result every hops gets 3 packets. We can make more reliable results by increasing this number with the -q . In the following example we send 5 packets to every hop.

traceroute -q 5 example.com

This sends 5 queries per hop instead of the default 3.

3. Set the Maximum Number of Hops

By default the traceroute command do not have any hop limit. Hop means the intermediate hosts or network devices those transmits packets to the destination. We can limit hops with the -q option. This prevents transmission of the packet more than 5 hops.

traceroute -m 20 example.com

Limits the number of hops to 20.

4. Set the Time to Live (TTL)

We can set start number of the hop. This will hide specified number of first hops in the output.

traceroute -f 5 example.com

Starts tracing from the 5th hop, skipping the first 4.

5. Specify the Packet Size

We can specify the size or the traceroute packets. The -s option is used to set packet size as b. In the following example we use 64 bytes for the traceroute packets.

traceroute -s 64 example.com

Uses a packet size of 64 bytes for the traceroute.

6. Use a Different Protocol

By default traceroute use the UDP packets. But we can change the protocol and use ICMP packets with the -I option.

traceroute -I example.com

Uses ICMP ECHO for tracing instead of the default UDP packets.

7. Specify a Source Interface

We can set the source network interface for the traceroute packets with the -i option. In the following example we set eth0 as the source interface for traceroute.

traceroute -i eth0 example.com

Sends packets through the eth0 network interface.

8. Set the Initial TTL

traceroute -f 10 example.com

Starts tracing with an initial TTL of 10, ignoring the first 9 hops.

9. Specify a Port Number

We can set destination port number with the -p option.

traceroute -p 8080 example.com

Sets the destination port to 8080.

10. Display the Hostnames Only

By default traceroute prints the domain names if they can be resolved. We can disable domain name display and only show IP addresses with the -n option.

traceroute -n example.com

Displays only the IP addresses of the hops, skipping DNS lookups.

11. Display AS Numbers

Internet consist of multiple autonous networks/systems. We can display AS numbers with the -A while using traceroute.

traceroute -A example.com

Displays the Autonomous System (AS) numbers along with the IP addresses.

12. Increase Timeout for Each Probe

We can set custom timout to prevent network related errors. The -w option is used to set timeout as seconds.

traceroute -w 3 example.com

Sets the timeout for each probe to 3 seconds.

13. Use IPv6 Instead of IPv4

The traceroute commands use IPv4 but we can change it into IPv6 by using the -6 option like below.

traceroute -6 example.com

Performs a traceroute using IPv6.

14. Use TCP SYN Packets

We can use the TCP SYNC packets for the traceroute with the -T.

traceroute -T example.com

Uses TCP SYN packets instead of the default UDP.

15. Set a Specific Number of Probes per Hop

traceroute -q 2 example.com

Sends 2 probes per hop.

16. Set the TTL Increment

We can specify specific gateway for the traceroute. The gateway IP address is specified with the -g option.

traceroute -g 192.168.1.1 example.com

Routes packets through the specified gateway (192.168.1.1).

17. Use ICMP ECHO Requests

traceroute -I example.com

Uses ICMP ECHO requests instead of UDP packets.

18. Perform a Loose Source Routing

traceroute -R example.com

Performs loose source routing, displaying the return path.

19. Use a Specific Protocol

traceroute -P TCP example.com

Uses the TCP protocol for the traceroute.

20. Specify the Maximum Wait Time for a Response

We can specify the maximum wait time for the response which will prevent long waits end stops the traceroute. The -w option is used to specify wait time for response as seconds.

traceroute -w 5 example.com

Sets the maximum wait time for a response to 5 seconds.

These examples cover a wide range of traceroute functionalities and options, making it easier to diagnose and analyze network paths and issues.

© 2024 Linux and Python Tutorials

🌱 Powered by Hugo with theme Dream.