Traceroute command explained
Traceroute is a built-in command with a command-line interface that you can use through the Terminal application. It serves as a diagnostic tool most commonly used to trace a route from the computer, sending the traceroute request to a hostname or IP address. It will send the query and get back a result, showing the query’s route and statistics about time and packets lost.
You can find Traceroute on Linux (almost all distros), macOS, Windows (there it is called tracert), and even Android (though you will need extra installation).
The software’s benefits are that it is free, easy to use, and serves well its purpose of tracing the route to a target.
How does traceroute work?
When you are using the traceroute, your device will send packets of data starting from your IP address, going through various hops, and reaching its target – hostname or IP address. The software will use packets with a short TTL (time to live) value and listen for the ICMP replays. The probes continue until a message “port unreachable (ICMP) or rest (TCP), which will indicate host.
As a result, you will see TTLs, addresses of the hops, and round time per probe, and extra data if you used some of the options.
If you need more detailed information about the Traceroute command we recommend you this article – Traceroute command and its options
Traceroute syntax Linux
To get to the syntax on Linux, you will need to write the following in the Terminal:
$traceroute –help
traceroute [options] host_Address [pathlength]
You will also see all the options for the traceroute command on Linux. They will help you perform better probes and get richer results.
Traceroute Linux options
This is a complete list of Traceroute options on Linux. Use it on Debian, Ubuntu, CentOS, or whatever distro you have.
Option/flag | Description |
-d –debug | This will allow socket level debugging in case that the kernel supports it. |
-4 | Only use IPv4. Yhe default will give results for IPv4 and IPv6 both. |
-6 | Only use IPv6. |
-T | Specify only TCP for the probes. |
-I | Specify only ICMP ECHO for the probes. |
-F | Forbid packet’s fragmentation. |
-f first_ttl | Set, TTL value for starting (default is 1). |
-g gateway | Say through which gateway you want the query to pass. |
-i interface | Decide which interface to use for traceroute. |
-m max_ttl | Set the maximum hop number (default is 30). |
-N squeries | Set the number of queries send simultaneously (default is 16). |
-n | Don’t map the IP addresses to the hostnames. |
-p port | Choose the port for probing. |
-t tos | Type of service and precedence value. |
-w waittime | The waiting time for probes (default is 5 seconds). |
-q nqueries | The number of packets per hop (default is 3 seconds). |
-r | Send directly to a host, bypassing the normal routing table. |
-s source_addr | Alternative source address. |
-z sendwait | The minimum interval, between sending of packets (default is 0). |
-e | See the ICMP extensions. |
-V | See the version and exit. |
-U | UDP for the probes. |
-UL | UDPLITE for the probes. |
-P protocol | Choose the protocol for the probes. |
Suggested article: How to use the MTR command?
Traceroute syntax for macOS and Windows?
Here we are focused on Linux-only, but not to be bad with the rest of the readers, we will tell you how to use traceroute on macOS and Windows.
- macOS
Use the Terminal. Traceroute exists, and it is very similar. The syntax for macOS is:
traceroute [options] host [packetsize]
To see all the options, you can write:
Traceroute –help
- Windows 10
On Windows, the Traceroute command has a slightly different name – tracert. The functionality is very similar.
The tracert sytax is:
tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name
It shows all the available options like –R for roundtrip, -S srcaddr source address, -4 for IPv4, and -6 for IPv6.
Conclusion
Traceroute is an easy to use, fast, and small command that you can easily use, no matter your Linux distro. Use it to monitor your servers or other network diagnostics.