Understanding of routing related instructions and concepts

Posted by webworks on Thu, 10 Mar 2022 11:51:37 +0100

Detailed explanation of route command parameters, adding and deleting route commands in linux

The route command of linux system is used to display and operate the IP routing table (show / manage the IP routing table). To realize the communication between two different subnets, a router connecting the two networks or a gateway located in both networks is needed. In the linux system, routing is usually set to solve the following problems: the linux system is in the LAN. There is a gateway in the LAN that allows the machine to access the Internet, so it is necessary to set the IP address of this machine as the default routing of the linux machine. It should be noted that adding a route by directly executing the route command on the command line will not be permanently saved. After the network card or machine is restarted, the route will become invalid; It can be found in / etc / RC Add the route command in local (startup file) to ensure that the route setting is permanently valid.

1. Command format:

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric] [if Interface]]

2. Command function:
The route command is used to operate the kernel based ip routing table. Its main function is to create a static route for a specified host or network to pass through a network interface, such as eth0. When "add" or "del" parameters are used, the routing table is modified. If there are no parameters, the current content of the routing table is displayed.

3. Command parameters:

-n Do not resolve names
-v Display detailed processing information
-F Display send message
-C Show route cache
-f Clear the routing table of all gateway entries
-p And add Make the route permanent when used with the command

add:Add a new route.
del:Delete a route.
-net:The destination address is a network.
-host:The destination address is a host.
netmask:When adding a network route, you need to use a netmask.
gw:Route packets through the gateway. Note that the gateway you specify must be reachable.
metric: Set the number of routing hops.
Command Specify the command you want to run (Add/Change/Delete/Print).  
Destination Specify the network destination for this route. 
mask Netmask Specifies the netmask (also known as subnet mask) associated with the network target. 
Gateway Specifies the forward or next hop that can be reached by the address set and subnet mask defined by the network target IP Address. 
metric Metric Specify an integer cost value for the route (from 1 to 9999), when in the route table(Best match with the destination address of the forwarded packet)Can be used when selecting from multiple routes. 
if Interface Specify the interface index for the interface that can access the target. To get a list of interfaces and their corresponding interface indexes, use route print Display function of command. You can use decimal or hexadecimal values for interface indexing.

4. Application examples:
Example 1: display the current route
Command:

route 
route -n

Output:

[root@prometheus01 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 ens33
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 ens33
192.168.172.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33

[root@prometheus01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.172.2   0.0.0.0         UG    0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
192.168.172.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33

explain:

The third line indicates that the address of the host network is 192.168.172.0,If the data transmission target is to communicate in the local area network, it can be directly transmitted through ens33 Forward packet
 The first line indicates that the purpose of data transmission is access Internet,Interface ens33,Send packets to gateway 192.168.172.2
 among Flags Is a routing flag that marks the status of the current network node
Flags Sign Description:
U  Up,Indicates that this route is currently started
H  Host,Indicates that this gateway is a host
G  Gateway,Indicates that this gateway is a router
R  Reinstate Route,Reinitialized routes using dynamic routes
D  Dynamically,This route is written dynamically
M  Modified,This route is dynamically modified by the route daemon or director
!  Indicates that this route is currently closed

remarks:
List the names faster than - n

Example 2: adding a gateway
Command:

route add -net 224.0.0.0 netmask 240.0.0.0 dev ens33

Output:

[root@prometheus01 ~]# route add -net 224.0.0.0 netmask 240.0.0.0 dev ens33
[root@prometheus01 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 ens33
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 ens33
192.168.172.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33
224.0.0.0       0.0.0.0         240.0.0.0       U     0      0        0 ens33

explain:
Add a route to 224.0.0.0

Example 3: shielding a route
Command:

route add -net 224.0.0.0 netmask 240.0.0.0 reject

Output:

[root@prometheus01 ~]# route add -net 224.0.0.0 netmask 240.0.0.0 reject
[root@prometheus01 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 ens33
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 ens33
192.168.172.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33
224.0.0.0       -               240.0.0.0       !     0      -        0 -
224.0.0.0       0.0.0.0         240.0.0.0       U     0      0        0 ens33

explain:
Add a shielded route with the target address of 224 x. X.x will be rejected

Example 4: delete routing record
Command:

route del -net 224.0.0.0 netmask 240.0.0.0
route del -net 224.0.0.0 netmask 240.0.0.0 reject

Output:

[root@prometheus01 ~]# route del -net 224.0.0.0 netmask 240.0.0.0
[root@prometheus01 ~]# route del -net 224.0.0.0 netmask 240.0.0.0 reject
[root@prometheus01 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 ens33
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 ens33
192.168.172.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33

Example 5: deleting and adding default gateways
Command:

route add default gw 192.168.172.100   
route del default gw 192.168.172.100

Output:

[root@prometheus01 ~]# route add default gw 192.168.172.100   
[root@prometheus01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.172.100 0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.172.2   0.0.0.0         UG    0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
192.168.172.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33

[root@prometheus01 ~]# route del default gw 192.168.172.100
[root@prometheus01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.172.2   0.0.0.0         UG    0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
192.168.172.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33

Detailed explanation of traceroute command

traceroute is an important application of ICMP Protocol, which is mainly used to detect the route from the source host to the destination host. traceroute uses ICMP message and TTL field in ip header. The principle is very simple. At the beginning, it sends a UDP datagram with TTL field of 1, and then sends a UDP packet with TTL field plus 1 every time it receives ICMP timeout message to determine each router in the path, and each router will return an ICMP timeout message when it discards UDP datagram, After finally reaching the destination host, ICMP selects an impossible value as the UDP port (greater than 30000). In this way, the destination host will send an ICMP error message that the port is unreachable.

Through traceroute, we can know the path of information from your computer to the host at the other end of the Internet. Each time a packet arrives at the same destination from the same source, the path may be different, but basically the route is the same most of the time. In linux system, we call it traceroute and in windows it is tracert. Traceroute measures how long it takes by sending a small packet to the destination device until it returns. Each device traceroute on a path should be tested three times. The output results include the time (ms) of each test, the name of the device (if any) and its IP address.

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

traceroute hostname

In the window system, the tracert command is executed:

tracert hostname

1. Command format:

traceroute [parameter][host]

2. Command function:
The traceroute command allows you to track the routing path of network packets. The default packet size is 40bytes, which can be set by users separately.
Specific parameter format:

traceroute [-dFlnrvx][-f<Survival value>][-g<gateway>...][-i<network interface>][-m<Survival value>][-p<Communication port>][-s<Source address>][-t<Service type>][-w<Timeout seconds>][Host name or IP address][Packet size]

3. Command parameters:

-d use Socket Level debugging function.
-f Set the survival value of the first detection packet TTL The size of the.
-F Set not to leave the off position.
-g Set up 8 source routing gateways at most.
-i Send packets using the specified network interface.
-I use ICMP Response substitution UDP Data information.
-m Set the maximum survival value of the detection packet TTL The size of the.
-n Direct use IP Address, not host name.
-p set up UDP Communication port of transmission protocol.
-r Ignore ordinary Routing Table,Send packets directly to the remote host.
-s Set the number of packets sent by the local host IP Address.
-t Set the of detection packets TOS Numerical value.
-v Displays the execution process of the instruction in detail.
-w Set the time to wait for the remote host to return.
-x Turns on or off the correctness check of the data packet.

4. Application examples:
Example 1: traceroute is the most commonly used and easy to use
Command:

traceroute www.baidu.com

Output:

[root@prometheus01 ~]# traceroute www.baidu.com
traceroute to www.baidu.com (180.101.49.11), 30 hops max, 60 byte packets
 1  172.16.108.2 (172.16.108.2)  0.388 ms 172.16.108.3 (172.16.108.3)  0.362 ms  0.446 ms
 2  172.16.90.10 (172.16.90.10)  0.082 ms  0.108 ms  0.136 ms
 3  101.226.183.193 (101.226.183.193)  24.288 ms  24.338 ms  24.414 ms
 4  114.80.98.21 (114.80.98.21)  0.746 ms  1.194 ms 114.80.98.17 (114.80.98.17)  0.800 ms
 5  101.95.208.121 (101.95.208.121)  1.233 ms 101.95.208.253 (101.95.208.253)  2.304 ms 101.95.208.225 (101.95.208.225)  2.128 ms
 6  101.95.218.221 (101.95.218.221)  1.346 ms 101.95.218.45 (101.95.218.45)  2.480 ms 101.95.218.49 (101.95.218.49)  1.824 ms
 7  202.97.74.134 (202.97.74.134)  4.057 ms 202.97.71.14 (202.97.71.14)  4.197 ms 202.97.74.122 (202.97.74.122)  4.958 ms
 8  58.213.94.146 (58.213.94.146)  7.496 ms 58.213.95.142 (58.213.95.142)  7.947 ms 58.213.94.138 (58.213.94.138)  8.492 ms
 9  * * *
10  58.213.96.58 (58.213.96.58)  7.523 ms 58.213.96.122 (58.213.96.122)  7.345 ms 58.213.96.94 (58.213.96.94)  7.378 ms
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

explain:
Records start from 1 according to the serial number. Each record is a hop. Each hop represents a gateway. We can see that each line has three times. The unit is ms, which is actually the default parameter of - Q. After detecting the data packet and sending three data packets to each gateway, the return time after the gateway responds; If you use traceroute -q 4 www.baidu.com COM, which means sending 4 data packets to each gateway.

Sometimes when we traceroute a host, we will see that some lines are represented by asterisks. In this case, the firewall may block the ICMP return information, so we can't get any relevant packet return data.

Sometimes, the gateway itself has a long delay, which may also be caused by a certain physical device. Of course, if a DNS fails to resolve the host name and domain name, there will also be a long delay; The - n parameter can be added to avoid DNS resolution and output data in IP format.

If you are between different network segments in the LAN, you can use traceroute to check whether the problem is the host problem or the gateway problem. If we access a server remotely and encounter problems, we use traceroute to track the gateway through which the packet passes and submit it to IDC service provider, which is also helpful to solve the problem; But at present, it seems that it is difficult to solve such problems in China. Even if we find the problem, IDC service providers cannot help us solve it.

Example 2: hop count setting
Command:

traceroute -m 10 www.baidu.com

Output:

[root@prometheus01 ~]# traceroute -m 10 www.baidu.com
traceroute to www.baidu.com (180.101.49.11), 10 hops max, 60 byte packets
 1  172.16.108.3 (172.16.108.3)  0.623 ms 172.16.108.2 (172.16.108.2)  0.352 ms  0.432 ms
 2  172.16.90.10 (172.16.90.10)  0.073 ms  0.109 ms  0.091 ms
 3  101.226.183.193 (101.226.183.193)  1.244 ms  1.280 ms  1.362 ms
 4  114.80.98.21 (114.80.98.21)  1.285 ms 114.80.98.17 (114.80.98.17)  7.011 ms 114.80.98.21 (114.80.98.21)  1.795 ms
 5  101.95.208.125 (101.95.208.125)  4.859 ms 101.89.240.161 (101.89.240.161)  9.176 ms 101.95.208.125 (101.95.208.125)  4.903 ms
 6  101.95.218.49 (101.95.218.49)  1.813 ms 101.95.218.237 (101.95.218.237)  1.959 ms 101.95.224.113 (101.95.224.113)  2.481 ms
 7  202.97.71.6 (202.97.71.6)  5.670 ms 202.97.66.62 (202.97.66.62)  8.000 ms 202.97.19.246 (202.97.19.246)  4.367 ms
 8  58.213.95.150 (58.213.95.150)  9.824 ms 58.213.95.158 (58.213.95.158)  8.650 ms 58.213.94.2 (58.213.94.2)  7.510 ms
 9  * 58.213.95.122 (58.213.95.122)  7.106 ms *
10  58.213.96.58 (58.213.96.58)  7.829 ms 58.213.96.66 (58.213.96.66)  7.503 ms 58.213.96.102 (58.213.96.102)  8.195 ms

Example 3: display the IP address without checking the host name
Command:

traceroute -n www.baidu.com

Output:

[root@prometheus01 ~]# traceroute -n  www.baidu.com   
traceroute to www.baidu.com (180.101.49.11), 30 hops max, 60 byte packets
 1  172.16.108.3  0.643 ms  0.671 ms 172.16.108.2  0.387 ms
 2  172.16.90.10  0.073 ms  0.103 ms  0.079 ms
 3  101.226.183.193  1.378 ms  1.448 ms  1.527 ms
 4  114.80.98.21  0.780 ms 114.80.98.17  0.752 ms 114.80.98.21  1.169 ms
 5  101.89.240.145  0.993 ms 101.95.208.125  1.242 ms 101.95.208.237  2.226 ms
 6  101.95.218.81  2.049 ms 101.95.218.197  1.792 ms 101.95.224.97  2.200 ms
 7  202.97.29.114  6.779 ms 202.97.66.202  8.024 ms 202.97.71.6  9.209 ms
 8  58.213.95.146  8.084 ms 58.213.94.106  7.459 ms 58.213.95.82  8.048 ms
 9  * * *
10  58.213.96.78  9.442 ms 58.213.96.130  7.112 ms 58.213.96.70  8.025 ms
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *


[root@prometheus01 ~]# traceroute  www.baidu.com   
traceroute to www.baidu.com (180.101.49.12), 30 hops max, 60 byte packets
 1  172.16.108.2 (172.16.108.2)  0.332 ms 172.16.108.3 (172.16.108.3)  0.392 ms  0.446 ms
 2  172.16.90.10 (172.16.90.10)  0.085 ms  0.103 ms  0.088 ms
 3  101.226.183.193 (101.226.183.193)  1.558 ms  1.640 ms  1.715 ms
 4  114.80.98.17 (114.80.98.17)  1.601 ms  2.045 ms 114.80.98.21 (114.80.98.21)  0.723 ms
 5  101.89.240.161 (101.89.240.161)  0.923 ms 101.95.208.229 (101.95.208.229)  1.233 ms 101.95.208.125 (101.95.208.125)  1.349 ms
 6  101.95.218.225 (101.95.218.225)  2.181 ms 101.95.218.81 (101.95.218.81)  2.096 ms  2.117 ms
 7  202.97.29.110 (202.97.29.110)  7.198 ms 202.97.19.254 (202.97.19.254)  4.183 ms 202.97.29.122 (202.97.29.122)  6.694 ms
 8  58.213.94.82 (58.213.94.82)  9.700 ms 58.213.94.110 (58.213.94.110)  8.729 ms 58.213.95.138 (58.213.95.138)  7.452 ms
 9  * * *
10  58.213.96.118 (58.213.96.118)  7.592 ms 58.213.96.54 (58.213.96.54)  8.163 ms 58.213.96.90 (58.213.96.90)  8.507 ms
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

Example 4: the basic UDP port setting used by the probe packet is 6888
Command:

traceroute -p 6888 www.baidu.com

Output:

[root@prometheus01 ~]# raceroute -p 6888 www.baidu.com
traceroute to www.baidu.com (180.101.49.12), 30 hops max, 60 byte packets
 1  172.16.108.2 (172.16.108.2)  0.379 ms  0.468 ms 172.16.108.3 (172.16.108.3)  0.443 ms
 2  172.16.90.10 (172.16.90.10)  0.075 ms  0.097 ms  0.078 ms
 3  101.226.183.193 (101.226.183.193)  1.168 ms  1.247 ms  1.364 ms
 4  114.80.98.21 (114.80.98.21)  0.627 ms 114.80.98.17 (114.80.98.17)  0.569 ms 114.80.98.21 (114.80.98.21)  0.989 ms
 5  101.95.208.229 (101.95.208.229)  1.283 ms * *
 6  * 101.95.218.225 (101.95.218.225)  2.232 ms 101.95.218.217 (101.95.218.217)  2.096 ms
 7  202.97.29.106 (202.97.29.106)  12.640 ms 202.97.101.42 (202.97.101.42)  6.908 ms 202.97.101.34 (202.97.101.34)  3.744 ms
 8  * 58.213.95.158 (58.213.95.158)  6.631 ms 58.213.94.142 (58.213.94.142)  8.190 ms
 9  * 58.213.94.126 (58.213.94.126)  7.514 ms *
10  58.213.96.110 (58.213.96.110)  7.517 ms 58.213.96.74 (58.213.96.74)  7.949 ms 58.213.96.50 (58.213.96.50)  7.467 ms
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

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

traceroute -q 4 www.baidu.com

Output:

[root@prometheus01 ~]# traceroute -q 4 www.baidu.com
traceroute to www.baidu.com (180.101.49.12), 30 hops max, 60 byte packets
 1  172.16.108.2 (172.16.108.2)  0.366 ms 172.16.108.3 (172.16.108.3)  0.468 ms  0.547 ms 172.16.108.2 (172.16.108.2)  0.427 ms
 2  172.16.90.10 (172.16.90.10)  0.081 ms  0.123 ms  0.117 ms  0.103 ms
 3  101.226.183.193 (101.226.183.193)  1.295 ms  1.380 ms  1.500 ms  1.580 ms
 4  114.80.98.21 (114.80.98.21)  0.687 ms 114.80.98.17 (114.80.98.17)  0.634 ms 114.80.98.21 (114.80.98.21)  1.046 ms  1.363 ms
 5  101.89.240.165 (101.89.240.165)  2.067 ms 101.95.208.217 (101.95.208.217)  2.954 ms 101.89.240.173 (101.89.240.173)  2.065 ms 101.95.208.233 (101.95.208.233)  2.201 ms
 6  101.95.218.225 (101.95.218.225)  1.991 ms 101.95.218.61 (101.95.218.61)  1.682 ms 101.95.218.73 (101.95.218.73)  2.530 ms 101.95.218.77 (101.95.218.77)  2.181 ms
 7  202.97.29.106 (202.97.29.106)  8.079 ms 202.97.101.34 (202.97.101.34)  4.216 ms 202.97.101.50 (202.97.101.50)  3.779 ms 202.97.81.118 (202.97.81.118)  16.144 ms
 8  58.213.95.146 (58.213.95.146)  7.450 ms 58.213.95.106 (58.213.95.106)  7.968 ms 58.213.94.110 (58.213.94.110)  9.789 ms  7.526 ms
 9  * * 58.213.95.90 (58.213.95.90)  7.129 ms *
10  58.213.96.94 (58.213.96.94)  7.667 ms 58.213.96.54 (58.213.96.54)  8.129 ms 58.213.96.118 (58.213.96.118)  7.551 ms 58.213.96.102 (58.213.96.102)  8.385 ms
11  * * * *
12  * * * *
13  * * * *
14  * * * *
15  * * * *
16  * * * *
17  * * * *
18  * * * *
19  * * * *
20  * * * *
21  * * * *
22  * * * *
23  * * * *
24  * * * *
25  * * * *
26  * * * *
27  * * * *
28  * * * *
29  * * * *
30  * * * *

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@prometheus01 ~]# traceroute -r www.baidu.com
traceroute to www.baidu.com (180.101.49.11), 30 hops max, 60 byte packets
connect: Network is unreachable

Example 7: set the waiting response time of outgoing detection packets to 3 seconds
Command:

traceroute -w 3 www.baidu.com

Output:

[root@prometheus01 ~]# traceroute -w 3 www.baidu.com
traceroute to www.baidu.com (180.101.49.11), 30 hops max, 60 byte packets
 1  172.16.108.2 (172.16.108.2)  0.429 ms 172.16.108.3 (172.16.108.3)  0.338 ms  0.403 ms
 2  172.16.90.10 (172.16.90.10)  0.071 ms  0.105 ms  0.093 ms
 3  101.226.183.193 (101.226.183.193)  1.483 ms  1.561 ms  1.645 ms
 4  114.80.98.21 (114.80.98.21)  9.103 ms 114.80.98.17 (114.80.98.17)  2.126 ms 114.80.98.21 (114.80.98.21)  13.809 ms
 5  101.95.208.245 (101.95.208.245)  1.923 ms 101.89.240.173 (101.89.240.173)  4.183 ms 101.95.208.253 (101.95.208.253)  1.937 ms
 6  101.95.224.97 (101.95.224.97)  2.216 ms 101.95.218.213 (101.95.218.213)  2.240 ms 101.95.218.205 (101.95.218.205)  1.466 ms
 7  202.97.81.162 (202.97.81.162)  7.006 ms 202.97.29.126 (202.97.29.126)  7.590 ms 202.97.66.198 (202.97.66.198)  7.971 ms
 8  58.213.95.106 (58.213.95.106)  7.314 ms 58.213.95.146 (58.213.95.146)  7.386 ms 58.213.94.82 (58.213.94.82)  8.424 ms
 9  * 58.213.94.126 (58.213.94.126)  7.814 ms 58.213.94.134 (58.213.94.134)  8.626 ms
10  58.213.96.58 (58.213.96.58)  8.124 ms 58.213.96.110 (58.213.96.110)  7.296 ms 58.213.96.118 (58.213.96.118)  7.683 ms
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

How Traceroute works:

The simplest basic usage of Traceroute is traceroute hostname

Traceroute program is designed to use the TTL (Time To Live) field of ICMP and IP header. Firstly, traceroute sends an IP datagram with TTL of 1 (in fact, three 40 byte packets are sent each time, including source address, destination address and time tag of packet sending) to the destination. When the first router on the path receives this datagram, it reduces the TTL by 1. At this time, the TTL becomes 0, so the router will discard this datagram and send back an "ICMP time exceeded" message (including the source address of the IP packet, all contents of the IP packet and the IP address of the router). After receiving this message, traceroute will know that the router exists on this path, and then traceroute will send another datagram with TTL 2, Found 2nd router Traceroute adds 1 to the TTL of the sent datagram every time to find another router. This repeated action continues until a datagram arrives at the destination. When the datagram arrives at the destination, the host will not send back the ICMP time exceeded message because it is already the destination. How does traceroute know that the destination has arrived?

When traceroute sends UDP datagrams to the destination, the port number it chooses to deliver is a number that ordinary applications will not use (more than 30000). Therefore, when this UDP datagram reaches the destination, the host will send back a message of "ICMP port unreachable". When traceroute receives this message, it will know that the destination has arrived. Therefore, traceroute has no so-called Daemon program on the Server side.

Traceroute extracts the IP address of the device sending ICMP TTL expiration message 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, and the time spent on each round trip of the three packets.

Detailed explanation of tracert

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 lifetime (TL) to the destination. Each router on the path should reduce its TTL value by at least 1 before forwarding the ICMP response message, so TTL is a valid jump 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 TTL of 1 and increasing the TTL value by 1 each time in subsequent transmission until the target response or reaches the maximum TTL value. The router can be determined by checking the ICMP timeout information sent back by the intermediate router. Note that some routers "quietly" discard messages with expired time to live (TLS) and are invalid for tracert.

Parameters:

-d Specifies that the computer name does not resolve addresses.
-h maximum_hops Specifies the maximum number of jumps to find the target.
-jcomputer-list Specify in computer-list Loose source routing in.
-w timeout Wait by timeout The number of milliseconds specified for each response.
target_name The name of the target computer.

Topics: Linux network