The network is an important part of the system administration. Because without a network the server has nothing to do. While administrating Linux servers troubleshooting network is very important. When a network problem occurs in a Linux server first step is checking network services and the route information. Network services can be checked with
systemctl or similar commands. Network routes can be checked with different tools but the most popular and straightforward tool is
traceroute . We will look at usage examples of traceroute in this tutorial.
Networking is a stand-alone profession done by its professionals. But some simple tools need to know by system administrators. Traceroute mainly uses
ICMP packets. ICMP is a protocol mainly developed for network troubleshooting and information sharing. ICMP packets are transmitted between network-capable devices to share information about network traffic. ICMP packets have TTL value. TTL is time to live where holds information about hop count. Generally, all network devices are one hop and as an example when ICMP packets send to
The syntax of the traceroute is like below.
Usage: traceroute [options] host [ packetlen ]
Help about traceroute commands can get like below.
Find Route To The Host, IP Address, Website
As we stated before traceroute will find the route to the given destination like host, IP address, website, etc. In this example, we will route to the site named but the destination can be an IP address or hostname in a local area network.
$ traceroute poftut.com
This example provides information about the route. There are 18 hops to the destination. Which is shown in the first column. In the second column, the hop names are provided. and in the other columns, the operation metrics are provided. If we look to the example we see that
* * * lines. Those are used to inform that these hops do not provide information about themselves.
Show IP Address Do Not Resolve Host Name
In the previous example, the hosts are expressed with their hostnames. Hostnames give more clues about the host. But the disadvantage of the hostname is that it should be resolved. As we know all operation is done with IP addresses but the IP addresses are expressed with their hostnames by using DNS. This will slow the trace operation. The
-n option can be used to disable hostname resolution.
$ traceroute -n poftut.com
Set Response Time
By tracing the path the ICMP packet transmission will occur. We will send the ICMP packet to the destination hop and we will wait for the answer. Sometimes this answer can come back late or never came back. This will slow our network trace operation. We can set time for the response and make our network trace operation faster. In the example, we set a timeout for the trace 1 second with
$ traceroute -n -w 1 poftut.com
Set Number Of Queries Per-Hop
We send ICMP packets to the hop and this hop sends back responses. We call this round trip as a query. Traceroute by default makes 3 queries for each hop. This is a changeable property. This can be changed with
-q parameter. In the following example, we set the query count as 1 for each hop.
$ traceroute -n -q 1 poftut.com
Set TTL For ICMP
We have previously talked about the TTL value. By default, this TTL value is set as 30. This means that we can only reach up to 30 hops. Because in each hop this TTL value is incremented and after hop number 30 the TTL will be 0 and the packet will not be transmitted to the next hop. In this example, we will set TTL number 8 which will only reach the first 8 hops.
$ traceroute -m 8 poftut.com
Set Start TTL
By default, the traceroute command will show all hops starting from 1 to the last hop. In some situations, we only need only some part of the hops starting from the n’th hop. This can be set with the
-f option. In this example, we will start from hop number 10.
$ traceroute -f 10 poftut.com
Print Autonomous System (AS) Numbers
The Internet is a very big public network. There are a lot of parties that provide connections for each other in a mesh topology. These parties are generally ISP’s or big companies and those are called in internet terminology as Autonomous Systems. All AS’s have their unique identifiers called AS numbers. While hoping in different AS’s their AS numbers can be printed with
$ traceroute -A poftut.com
We can see the AS numbers like
[AS9121] after the IP address of hop.
Specify Source Interface
In enterprise environments, Linux systems generally have multiple interfaces for high availability. Multiple interfaces mean multiple paths to the destination. Linux has default routes which mean primary interfaces for out of network destinations. This is used by default but we can specify another interface with the
-i option. But first, we will list available interfaces with the
$ ip link
Now we will specify the network device name. But keep in mind that these options require root privileges which can be provided with
$ sudo traceroute -i ens3 poftut.com
IP packets are firstly redirected to the host where it’s specified in the network configuration of the source system. This first hop/host is called a gateway. By default, this gateway is used by traceroute. We can change this gateway information with the
-g option. In this example, we will set IP address
192.168.122.1 as gateway address.
$ sudo traceroute -g 192.168.122.1 poftut.com