当前位置: 首页 > 编程文章 >

Linux traceroute命令参数详解与使用示例

Linux traceroute命令参数详解与使用示例

作者:沈安时间:2025-07-16 12:46:04浏览:516

traceroute是Linux系统中用于追踪数据包从源主机到目标主机所经过路径的网络诊断工具。虽然相同起点和终点的路由可能因网络状况变化而不同,但大部分情况下路径保持一致。该命令支持丰富的参数配置,如通过-n显示IP而非主机名、-m限制最大跳数、-q设置探测包数量、-w调整等待时间以及-p指定UDP端口等,帮助用户灵活排查网络连通性问题。

本文目录展开

traceroute功能原理与路径特性

利用traceroute工具,用户可以了解数据报文从本地计算机传输至互联网远端主机的具体路由轨迹。尽管在特定源地址(source)指向特定目的地址(destination)时,每次数据包的实际传输路径可能存在差异,但在绝大多数场景下,其遵循的骨干路由路径是相对固定的。

常用命令参数详细说明

常用命令参数说明


Options:
 -4             Use IPv4
 -6             Use IPv6
 -d --debug         Enable socket level debugging
 -F --dont-fragment     Do not fragment packets
 -f first_ttl --first=first_ttl
               Start from the first_ttl hop (instead from 1)
 -g gate,... --gateway=gate,...
               Route packets through the specified gateway
               (maximum 8 for IPv4 and 127 for IPv6)
 -I --icmp         Use ICMP ECHO for tracerouting
 -T --tcp          Use TCP SYN for tracerouting
 -i device --interface=device
               Specify a network interface to operate with
 -m max_ttl --max-hops=max_ttl
               Set the max number of hops (max TTL to be
               reached). Default is 30
 -N squeries --sim-queries=squeries
               Set the number of probes to be tried
               simultaneously (default is 16)
 -n             Do not resolve IP addresses to their domain names
 -p port --port=port    Set the destination port to use. It is either
               initial udp port value for "default" method
               (incremented by each probe, default is 33434), or
               initial seq for "icmp" (incremented as well,
               default from 1), or some constant destination
               port for other methods (with default of 80 for
               "tcp", 53 for "udp", etc.)
 -t tos --tos=tos      Set the TOS (IPv4 type of service) or TC (IPv6
               traffic class) value for outgoing packets
 -l flow_label --flowlabel=flow_label
               Use specified flow_label for IPv6 packets
 -w waittime --wait=waittime
               Set the number of seconds to wait for response to
               a probe (default is 5.0). Non-integer (float
               point) values allowed too
 -q nqueries --queries=nqueries
               Set the number of probes per each hop. Default is
               3
 -r             Bypass the normal routing and send directly to a
               host on an attached network
 -s src_addr --source=src_addr
               Use source src_addr for outgoing packets
 -z sendwait --sendwait=sendwait
               Minimal time interval between probes (default 0).
               If the value is more than 10, then it specifies a
               number in milliseconds, else it is a number of
               seconds (float point values allowed too)
 -e --extensions      Show ICMP extensions (if present), including MPLS
 -A --as-path-lookups    Perform AS path lookups in routing registries and
               print results directly after the corresponding
               addresses
 -M name --module=name   Use specified module (either builtin or external)
               for traceroute operations. Most methods have
               their shortcuts (`-I' means `-M icmp' etc.)
 -O OPTS,... --options=OPTS,...
               Use module-specific option OPTS for the
               traceroute module. Several OPTS allowed,
               separated by comma. If OPTS is "help", print info
               about available options
 --sport=num         Use source port num for outgoing packets. Implies
               `-N 1'
 -U --udp          Use UDP to particular port for tracerouting
               (instead of increasing the port per each probe),
               default port is 53
 -UL             Use UDPLITE for tracerouting (default dest port
               is 53)
 -P prot --protocol=prot  Use raw packet of protocol prot for tracerouting
 --mtu            Discover MTU along the path being traced. Implies
               `-F -N 1'
 --back           Guess the number of hops in the backward path and
               print if it differs
 -V --version        Print version info and exit
 --help           Read this help and exit

典型命令执行展示

典型命令执行展示

组合命令应用实例

组合命令应用实例


traceroute -n -m 5 -q 4 -w 3 www.baidu.com

参数解释:-n 选项用于直接显示IP地址,跳过主机名解析过程;-m 选项用于设定探测的最大跳数限制。

-q 4 表示向每个网关发送4个探测数据包;-w 3 将接收外部探测包响应结果的超时等待时间设定为3秒。

探测过程中使用的基础UDP端口号被设置为6888。


traceroute -p 6888 www.baidu.com

-r 选项用于绕过系统正常的路由表查找机制,直接向与当前网络相连的主机发送探测请求。


traceroute -r www.baidu.com

以上内容涵盖了本文的核心知识点,旨在为读者的学习提供实际帮助,同时也欢迎读者持续关注本站以获取更多技术支持。

上一篇
Linux文件已删除但空间未释放的原因及排查解决方法

在Linux系统中执行rm命令删除大文件后,若该文件仍被进程打开或写入,内核不会立即回收其占用的磁盘块,导致df显示空间未释放。通过lsof | grep delete可定位此类僵尸文件,使用echo " " > /path/to/file清空内容即可在不重启服务的情况下恢复磁盘空间。

下一篇
Ubuntu修改密码及配置复杂度策略指南

本文介绍在Ubuntu系统中修改普通用户及root用户密码的方法,并详细讲解如何通过安装cracklib模块和配置PAM策略来增强系统安全性。内容涵盖禁止使用旧密码、设置最短长度、强制字符组合以及调整密码过期期限等关键步骤,帮助管理员有效防止弱口令风险。

相关文章

更多
Linux traceroute命令详解:原理、参数与多场景实战

traceroute通过发送带有递增TTL值的探测包,利用ICMP超时和端口不可达消息追踪数据包路径。本文详解其工作原理、常用参数(如-m限制跳数、-n跳过DNS解析)及在Linux下的多个实战案例,并对比Windows系统中tracert命令的异同,帮助排查网络延迟与断点问题。

2026.07.15 310
LINUX下PHP程序实现WORD文件转化为PDF文件的方法

本文介绍在LINUX环境下通过PHP程序将Word文件转换为PDF文件的具体实现方法。文中提供了相关的代码示例及参考链接,旨在帮助开发者解决文件格式转换需求,提升文档处理效率。

2026.11.12 1,000
Linux主机AMH管理面板安装与建站指南

AMH是一款独立的LNMP/Nginx虚拟主机管理面板,支持Centos、Debian和Ubuntu系统。本文介绍如何在纯净Linux系统中通过脚本安装AMH 4.2版本,包括设置MySQL和管理员密码。安装完成后,通过Web端配置虚拟主机、绑定域名、创建FTP账号及数据库,即可快速搭建网站。

2026.11.13 999
Linux内核container_of宏原理与实现解析

Linux内核中container_of宏用于通过结构体成员地址反推结构体首地址。其核心依赖于offsetof宏计算成员偏移量,利用( char *)ptr减去偏移量并强转为目标类型指针实现定位。该宏还包含类型检查机制以增强代码安全性。

2026.06.01 995
Linux、Windows 及源码安装 Git 完整指南

本文介绍在 Linux、Windows 系统及从源代码三个环境下安装 Git 的具体方法。Linux 用户可通过 yum 或 apt-get 使用包管理器快速部署;Windows 用户可选择官方 Git for Windows 安装包或 GitHub for Windows,后者提供图形界面与 PowerShell 支持;此外,文章还详细说明了通过编译源码获取最新版本的依赖库准备、下载及构建流程。

2026.06.03 993
Linux useradd 命令详解:群组与家目录配置实战

在 Linux 系统中,useradd 是用于创建或更新用户信息的底层命令。由于直接使用较为复杂,Debian 系发行版提供了 adduser 脚本作为简化封装。本文基于 Ubuntu14.04 环境,深入解析 useradd 在处理初始群组(-g/-G/-N)和家目录(-m/-d)时的具体行为差异,并通过多个实例展示如何精确控制用户登录 Shell、群组归属及目录结构。

2025.06.14 992

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。