Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the traceroute command in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use the traceroute command in Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use the traceroute command in Linux.

An introduction to the linux traceroute command is as follows:

Through traceroute, we can know the path of information from your computer to the host on the other side of the Internet. Of course, each packet from the same starting point (source) to a certain same destination (destination) may take a different path, but basically, most of the time the route is the same. In linux system, we call it traceroute, and in MS Windows, it is tracert. Traceroute measures how long it takes to send a small packet to the destination device until it returns. The traceroute of each device on a path is tested 3 times. The output includes the time of each test (ms) and the name of the device, if any, and its IP address.

In most cases, we will execute the command line directly under the linux host system:

Traceroute hostname

Under the Windows system, the command of tracert is executed:

Tracert hostname

1. Command format:

Traceroute [parameters] [host]

two。 Command function:

The traceroute command allows you to track the routing path of network packets. The default packet size is 40Bytes, which the user can set separately.

Specific parameter format: traceroute [- dFlnrvx] [- f] [- g...] [- I] [- m] [- p] [- s] [- t] [- w] [host name or IP address] [packet size]

3. Command parameters:

-d uses Socket-level troubleshooting capabilities.

-f sets the size of the survival value TTL of the first detection packet.

-F setting do not leave the break bit.

-g set source routing gateways. A maximum of 8 can be set.

-I send out packets using the specified network interface.

-I use ICMP responses instead of UDP data information.

-m sets the size of the maximum survival value TTL of the detection packet.

-n directly use the IP address instead of the host name.

-p sets the communication port of the UDP transport protocol.

-r ignores the normal Routing Table and sends the packet directly to the remote host.

-s sets the IP address of the packet sent by the local host.

-t sets the TOS value of the detection packet.

-v shows the execution of the instruction in detail.

-w sets the time to wait for a return from the remote host.

-x turns on or off the correctness check of the packet.

4. Examples of use:

The simple and most commonly used usage of example 1:traceroute

Command:

Traceroute www.baidu.com

Output:

[root@localhost ~] # traceroute www.baidu.com

Traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets

1 192.168.74.2 (192.168.74.2) 2.606 ms 2.771 ms 2.950 ms

2 211.151.56.57 (211.151.56.57) 0.596 ms 0.598 ms 0.591 ms

3 211.151.227.206 (211.151.227.206) 0.546 ms 0.544 ms 0.538 ms

4 210.77.139.145 (210.77.139.145) 0.710 ms 0.748 ms 0.801 ms

5 202.106.42.101 (202.106.42.101) 6.759 ms 6.945 ms 7.107 ms

6 61.148.154.97 (61.148.154.97) 718.908 ms * bt-228-025.bta.net.cn (202.106.228.25) 5.177 ms

7 124.65.58.213 (124.65.58.213) 4.343 ms 4.336 ms 4.367 ms

8 202.106.35.190 (202.106.35.190) 1.795 ms 61.148.156.138 (61.148.156.138) 1.899 ms 1.951 ms

9 *

30 *

[root@localhost ~] #

Description:

The record starts from 1 according to the serial number, and each record is a hop, and each hop represents a gateway. We can see that each row has three times in ms, which is actually the default parameter of-Q. Probe the time after the gateway responds after sending three packets to each gateway; if you use traceroute-Q 4 www.58.com, it means that four packets are sent to each gateway.

Sometimes when we traceroute a host, we see lines with asterisks. When this happens, it may be that the firewall has blocked the return information of ICMP, so we can't get any relevant packet return data.

Sometimes we have a long delay at a gateway, which may be due to the congestion of a gateway or to the physical device itself. Of course, if there is a problem with a DNS, there will be a long delay when the host name and domain name cannot be resolved. You can add the-n parameter to avoid DNS parsing and output the data in IP format.

If between different network segments in the local area network, we can use traceroute to find out what the problem is, whether it is the problem of the host or the gateway. If we encounter a problem when we access a server remotely, we use traceroute to track the gateway through which the packet passes and submit it to the IDC service provider, which will also help to solve the problem. But at present, it seems that it is more difficult to solve such a problem in China, even if we find the problem, the IDC service provider cannot help us solve it.

Example 2: hop count setting

Command:

Traceroute-m 10 www.baidu.com

Output:

[root@localhost] # traceroute-m 10 www.baidu.com

Traceroute to www.baidu.com (61.135.169.105), 10 hops max, 40 byte packets

1 192.168.74.2 (192.168.74.2) 1.534 ms 1.775 ms 1.961 ms

2 211.151.56.1 (211.151.56.1) 0.508 ms 0.514 ms 0.507 ms

3 211.151.227.206 (211.151.227.206) 0.571 ms 0.558 ms 0.550 ms

4 210.77.139.145 (210.77.139.145) 0.708 ms 0.729 ms 0.785 ms

5 202.106.42.101 (202.106.42.101) 7.978 ms 8.155 ms 8.311 ms

6 bt-228-037.bta.net.cn (202.106.228.37) 772.460 ms bt-228-025.bta.net.cn (202.106.228.25) 2.152 ms 61.148.154.97 (61.148.154.97) 772.107 ms

7 124.65.58.221 (124.65.58.221) 4.875 ms 61.148.146.29 (61.148.146.29) 2.124 ms 124.65.58.221 (124.65.58.221) 4.854 ms

8 123.126.198 (123.126.198) 2.944 ms 61.148.156.6 (61.148.156.6) 3.505 ms 123.126.198 (123.126.198) 2.885 ms

9 *

10 *

[root@localhost ~] #

Description:

Example 3: displays the IP address without looking up the hostname

Command:

Traceroute-n www.baidu.com

Output:

[root@localhost] # traceroute-n www.baidu.com

Traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets

1 211.151.74.2 5.430 ms 5.636 ms 5.802 ms

2 211.151.56.57 0.627 ms 0.625 ms 0.617 ms

3 211.151.227.206 0.575 ms 0.584 ms 0.576 ms

4 210.77.139.145 0.703 ms 0.754 ms 0.806 ms

5 202.106.42.101 23.683 ms 23.869 ms 23.998 ms

6 202.106.228.37 247.101 ms * *

7 61.148.146.29 5.256 ms 124.65.58.213 4.386 ms 4.373 ms

8 202.106.35.190 1.610 ms 61.148.156.138 1.786 ms 61.148.3.34 2.089 ms

9 *

30 *

[root@localhost ~] # traceroute www.baidu.com

Traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets

1 211.151.74.2 (211.151.74.2) 4.671 ms 4.865 ms 5.055 ms

2 211.151.56.57 (211.151.56.57) 0.619 ms 0.618 ms 0.612 ms

3 211.151.227.206 (211.151.227.206) 0.620 ms 0.642 ms 0.636 ms

4 210.77.139.145 (210.77.139.145) 0.720 ms 0.772 ms 0.816 ms

5 202.106.42.101 (202.106.42.101) 7.667 ms 7.910 ms 8.012 ms

6 bt-228-025.bta.net.cn (202.106.228.25) 2.965 ms 2.440 ms 61.148.154.97 (61.148.154.97) 431.337 ms

7 124.65.58.213 (124.65.58.213) 5.134 ms 5.124 ms 5.044 ms

8 202.106.35.190 (202.106.35.190) 1.917 ms 2.052 ms 2.059 ms

9 *

30 *

[root@localhost ~] #

Description:

Example 4: basic UDP port settings used by probe packets 6888

Command:

Traceroute-p 6888 www.baidu.com

Output:

[root@localhost] # traceroute-p 6888 www.baidu.com

Traceroute to www.baidu.com (220.181.111.147), 30 hops max, 40 byte packets

1 211.151.74.2 (211.151.74.2) 4.927 ms 5.121 ms 5.298 ms

2 211.151.56.1 (211.151.56.1) 0.500 ms 0.499 ms 0.509 ms

3 211.151.224.90 (211.151.224.90) 0.637 ms 0.631 ms 0.641 ms

4 *

5 220.181.70.98 (220.181.70.98) 5.050 ms 5.313 ms 5.596 ms

6 220.181.17.94 (220.181.17.94) 1.665 ms! X * *

[root@localhost ~] #

Description:

Example 5: set the number of probe packets to a value of 4

Command:

Traceroute-Q 4 www.baidu.com

Output:

[root@localhost] # traceroute-Q 4 www.baidu.com

Traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets

1 211.151.74.2 (211.151.74.2) 40.633 ms 40.819 ms 41.004 ms 41.188 ms

2 211.151.56.57 (211.151.56.57) 0.637 ms 0.633 ms 0.627 ms 0.619 ms

3 211.151.227.206 (211.151.227.206) 0.505 ms 0.580 ms 0.571 ms 0.569 ms

4 210.77.139.145 (210.77.139.145) 0.753 ms 0.800 ms 0.853 ms 0.904 ms

5 202.106.42.101 (202.106.42.101) 7.449 ms 7.543 ms 7.738 ms 7.893 ms

6 61.148.154.97 (61.148.154.97) 316.817 ms bt-228-025.bta.net.cn (202.106.228.25) 3.695 ms 3.672 ms *

7 124.65.58.213 (124.65.58.213) 3.056 ms 2.993 ms 2.960 ms 61.148.146.29 (61.148.146.29) 2.837 ms

8 61.148.3.34 (61.148.3.34) 2.179 ms 2.295 ms 2.442 ms 202.106.35.190 (202.106.35.190) 7.136 ms

9 *

30 *

[root@localhost ~] #

Description:

Example 6: bypass the normal routing table and send it directly to the host connected to the network

Command:

Traceroute-r www.baidu.com

Output:

[root@localhost] # traceroute-r www.baidu.com

Traceroute to www.baidu.com (61.135.169.125), 30 hops max, 40 byte packets

Connect: network is unreachable

[root@localhost ~] #

Description:

Example 7: set the waiting response time of the outgoing probe packet to 3 seconds

Command:

Traceroute-w 3 www.baidu.com

Output:

[root@localhost] # traceroute-w 3 www.baidu.com

Traceroute to www.baidu.com (61.135.169.105), 30 hops max, 40 byte packets

1 211.151.74.2 (211.151.74.2) 2.306 ms 2.469 ms 2.650 ms

2 211.151.56.1 (211.151.56.1) 0.621 ms 0.613 ms 0.603 ms

3 211.151.227.206 (211.151.227.206) 0.557 ms 0.560 ms 0.552 ms

4 210.77.139.145 (210.77.139.145) 0.708 ms 0.761 ms 0.817 ms

5 202.106.42.101 (202.106.42.101) 7.520 ms 7.774 ms 7.902 ms

6 bt-228-025.bta.net.cn (202.106.228.25) 2.890 ms 2.369 ms 61.148.154.97 (61.148.154.97) 471.961 ms

7 124.65.58.221 (124.65.58.221) 4.490 ms 4.483 ms 4.472 ms

8 123.126.198 (123.126.198) 2.948 ms 61.148.156.6 (61.148.156.6) 7.688 ms 7.756 ms

9 *

30 *

[root@localhost ~] #

Description:

How Traceroute works:

The simplest basic usage of Traceroute is: traceroute hostname

The Traceroute program is designed by using the TTL (Time To Live) field (field) of ICMP and IP header. First, traceroute sends an IP datagram with a TTL of 1 (in fact, three 40-byte packets at a time, including the source address, the destination address, and the time tag issued by the packet) to the destination, and when the first router (router) on the path receives the datagram, it subtracts the TTL by 1. At this point, the TTL becomes 0, so the router will drop the datagram and send back a "ICMP time exceeded" message (including the source address of the IP packet, all the contents of the IP packet and the IP address of the router). When traceroute receives this message, it knows that the router exists on this path, and then traceroute sends out another datagram with TTL 2 and discovers the second router. Each time traceroute adds one to the TTL of the outgoing datagram to find another router, this repetition continues until a datagram arrives at its destination. When datagram arrives at its destination, the host does not send back an ICMP time exceeded message because it is already a destination, so how does traceroute know that the destination has arrived?

When Traceroute sends a UDP datagrams to its destination, the port number it chooses to deliver is a number (more than 30000) that is not used by normal applications, so when the UDP datagram arrives at the destination, the host sends back a "ICMP port unreachable" message, and when traceroute receives this message, it knows that the destination has arrived. So there is no so-called Daemon program on the server side of traceroute.

Traceroute extracts the IP address of the device that sends ICMP TTL expiration messages and resolves the domain name. Each time, Traceroute prints out a series of data, including the domain name and IP address of the routing device it passes through, and the time it takes for the three packets to go back and forth.

Tracert of windows:

Format:

Tracert [- d] [- h maximum_hops] [- j host-list] [- w timeout] target_name

Parameter description:

Tracert [- d] [- h maximum_hops] [- j computer-list] [- w timeout] target_name

The diagnostic utility determines the route to the destination by sending Internet Control Information Protocol (CMP) response messages with different time to live (TL) to the destination. Each router on the path reduces its TTL value by at least 1 before forwarding the ICMP echo message, so TTL is a valid hop count. When the TTL value of the message is reduced to 0, the router sends back ICMP timeout information to the source system. Tracert can determine the route by sending the first response message with a TTL of 1 and incrementing the TTL value by 1 each time in subsequent transmissions until the target responds or the maximum TTL value is reached. The router can be determined by examining the ICMP timeout (ime Exceeded) information sent back by the intermediate router. Note that some routers "quietly" discard time-to-live (TLS) expired messages and have no effect on tracert.

Parameters:

-d specifies that the address is not resolved to the computer name.

The-h maximum_hops specifies the maximum number of jumps for the lookup target.

-jcomputer-list specifies that the source route is loose in the computer-list.

-w timeout waits for the number of milliseconds specified by timeout for each reply.

The name of the target_name target computer.

Example:

C:\ Users\ Administrator > tracert www.58.com

Tracing route to www.58.com [221.187.111.30]

Over a maximum of 30 hops:

1 1 ms 1 ms 1 ms 10.58.156.1

2 1 ms

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report