在Linux上,可以使用多种命令来查看经过的路由。下面是一些常用的命令和操作步骤:
1. 使用`route`命令: `route`命令可以显示和操作IP路由表。在终端中输入 `route -n` 命令,可以打印出详细的IP路由表。
“`$ route -n“`输出结果类似于:“`Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.1.1 0.0.0.0 UG 1024 0 0 eth010.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth1192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0“`
上面的输出中包含了目标网络、网关、子网掩码、标识符、度量值、引用、使用的接口等信息。
2. 使用`ip`命令: `ip`命令是Linux系统中的一个强大的网络配置工具。可以使用 `ip route` 命令来查看路由表。
“`$ ip route“`输出结果类似于:“`default via 192.168.1.1 dev eth0 proto static metric 102410.0.0.0/8 dev eth1 scope link192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 20“`
3. 使用`traceroute`命令: `traceroute` 命令用于跟踪数据包在网络上的传输路径。输入 `traceroute` 命令,后跟目标主机的IP地址或域名。
“`$ traceroute http://www.google.com“`输出结果类似于:“`traceroute to http://www.google.com (216.58.221.100), 30 hops max, 60 byte packets 1 gateway (192.168.1.1) 1.230 ms 2.562 ms 2.947 ms 2 * * * 3 10.0.0.1 (10.0.0.1) 3.768 ms 4.312 ms 5.026 ms 4 172.16.0.1 (172.16.0.1) 7.170 ms 8.902 ms 9.772 ms …“`
上面的输出结果中显示了数据包经过的每一跳的IP地址和往返时间。
4. 使用`mtr`命令: `mtr` 命令是一个网络诊断工具,可以追踪到目标主机,并实时显示每一跳的网络延迟。输入 `mtr` 命令,后跟目标主机的IP地址或域名。
“`$ mtr http://www.google.com“`输出结果类似于:“` My traceroute [v0.94]gateway.local (0.0.0.0) Wed Jul 29 14:38:29 2020Keys: Help Display mode Restart statistics Order of fields quit Packets Pings Host Loss% Snt Last Avg Best Wrst StDev 1. gateway (192.168.1.1) 0.0% 23 1.7 1.6 1.3 2.6 0.3 2. * 0.0% 23 5.9 5.7 4.6 7.1 0.5 3. 10.0.0.1 0.0% 23 3.3 4.2 3.3 5.4 0.6 4. 172.16.0.1 0.0% 23 7.2 6.7 4.9 9.3 0.9 …“`
上面的输出结果显示了每一跳的IP地址、丢包率、发送的数据包数量、最后一个数据包的往返时间和平均往返时间等信息。
可以根据具体的需求选择合适的命令和工具来查看经过的路由。以上提到的命令和工具都提供了丰富的选项,可以通过命令行参数来更详细地显示相关信息。