12.07.2024

How To Use traceroute in Linux?

Traceroute is a utility for testing the network connection path between devices. The main task of which is to display a list of devices involved in the transmission of the packet to the destination point. It works on network and transport layer protocols: TCP, UDP and ICMP. Also, unlike the ping utility, it can be used to build a network card.

What is the principle of operation?

In order for devices to communicate on the network, there are a number of rules by which information is transmitted. One of these requires adding a TTL parameter to each transmitted packet, which takes the standard value of 128 for PCs and 64 for mobile devices. Each time a packet passes through the router, the TTL value is reduced so that the packet is not looped. After all, when the value 0 is reached, the router deletes the packet and sends back the Time Exceed packet. Therefore, the principle of operation is as follows: traceroute sends ICMP packets with the parameters TTL=1, TTL=2, TTL=3 and so on, when the node responds with Time Exceed, the utility fixes the node.

How do I install traceroute?

Before installing the utility, you need to check if it is available on your device by requesting the package manager. To distribute using apt manager:

apt list | grep "traceroute"

If you are using an rpm-like package manager, the command will look like this:

dnf list | grep "traceroute"

Screenshot №1 — Installation traceroute

We use the package manager for installation:

apt update && apt upgrade \
apt install traceroute -y

For a RPM-like package manager, use the appropriate commands:

dnf update && dnf upgrade \
dnf install traceroute -y

Update the repositories and install the utility, turn to the hint and select useful options from the entire list:

traceroute

Screenshot №2 — Help page

This list provides a complete list of options that can be used for work. The -4 and -6 options allow you to specify the type of IPv4 or IPv6 protocol used. In order for the packets not to fragment, but to be transmitted entirely, the -F option is used. To change the protocol used to poll nodes, you can use the options -T for TCP packets, -I for ICMP connections, UDP is used by default.

Examples of utility's work

In order to check the path to the node, you need to write a command that addresses the target node:

traceroute google.com

Screenshot №3 — UDP traceroute

The screenshot shows the full path of the routers and redirecting devices that the packet passed through. According to them, it is possible to assume which networks are nested into each other, and which are on the same level.

It happens that the response packets do not arrive and asterisks remain in place of the node, as in line 5 in the screenshot. This is due to the fact that the node has closed the ports for connection using the protocol used. In such cases, you can try to use a TCP or ICMP connection, for example, let's try for google.com find out the 5th line:

traceroute -T google.com

Screenshot №4 — TCP traceroute

All steps in the tutorial can be performed on powerful cloud servers. Serverspace provides isolated VPS / VDS servers for common and virtualize usage.

Screenshot №5 — Create Server

It will take some time to deploy server capacity. After that you can connect in any of the convenient ways!