Traceroute command

By the name of this command, you already know what it does, but let’s go a bit deeper and see precisely how the Traceroute command works. When you learn how to use the Traceroute command, you will see how useful it is and how often you will need it in your daily network’s tasks.

What is the Traceroute command?

Traceroute is one of the built-in commands inside your OS (Linux, macOS, and even on Windows as a tracert command) that serves for network diagnostic and, more specifically, for tracing the route from a point to a target.

You can access it through the Terminal application and use it to target a hostname or an IP address. The query will give you information about each of the elements on the network, starting with the first hop, all the way to the target. You will get useful statistics. The results will show you how exactly a query travels. The information can help you understand the route better, see if there is some strange routing going on, and plan your future network expansion for better and faster query answering.

How does it work?

There are many routers spread all around the world that help us resolve domain names and other web services.

Traceroute command will show the exact path the packets of data takes to their target. When we trace the route from our computer, we will need to open the Terminal and type “traceroute + IP address” or “traceroute + hostname”. 

If we use Wikipedia, we can do it like this: 

traceroute wikipedia.org, or traceroute 91.198.174.192

The typical Traceroute command will send 3 packets of data, so you will get 3 columns of answers. 

Each time a packet reaches a router (hop), it will report back to us with the hostname, the IP address, and the response time. 

You will see each hop in a different line. The total number of lines you can see in the first column of the result and shows the total number of hops. 

You can see the data each hop returns and see if there is a problem. A particular hop could be taking a too long time to respond, so you can increase the waiting time. Another problem that could occur is that the packet might get lost, but thanks to the traceroute command, you will know where exactly they get lost. This will be the problematic point that you can focus on and fix it. 

It works differently from the ping command because the Traceroute not only sends packets to the target but also pings each router on the way to the target and measures the route trip time for each of the routers.

The data packets have TTL values that show how far they can go. By default, it is set to 30, but you can set it to more or less. The value exists, so no packets are traveling forever on the Internet.

Traceroute command options

Here you have a few important options that you can try with the Traceroute command for more specific queries: 

traceroute -m 35 wikipedia.org 

In this case, we increased the TTL to 35, so if we are further away from our target, we will have 5 more hops to reach it than the default 30. 

traceroute -w 60 wikipedia.org

You can also increase the time to wait, not just the number of hops. That way, you can wait longer for a response but actually get one. 

traceroute -q 8 wikipedia.org

Here we are increasing the number of packets to 8, from the default 3. We can have a better view of the network with more packets sent. 

traceroute -T wikipedia.org

With the Traceroute command, you can change the interface for your query. In this case, we use T for TCP, but you can use -I for ICMP or -I for IP.