菜鸟宝典:常用的网络命令集

发布时间:2007年02月24日      浏览次数:3092 次
如果你玩过路由器的话,就知道路由器里面那些很好玩的命令缩写。
  例如,"sh int" 的意思是 "show interface"。
  现在 windows 2000 也有了类似界面的工具,叫做 netsh。
  我们在 windows 2000 的 cmd shell 下,输入 netsh
  就出来:netsh> 提示符,
  输入 int ip 就显示:
  interface ip>
  然后输入 dump ,我们就可以看到当前系统的网络配置:
  # ----------------------------------
  # interface ip configuration
  # ----------------------------------
  pushd interface ip
  # interface ip configuration for "local area connection"
  set address name = "local area connection" source = static addr = 192.168.1.168
  mask = 255.255.255.0
  add address name = "local area connection" addr = 192.1.1.111 mask = 255.255.255.0
  set address name = "local area connection" gateway = 192.168.1.100 gwmetric = 1
  set dns name = "local area connection" source = static addr = 202.96.209.5
  set wins name = "local area connection" source = static addr = none
  popd
  # end of interface ip configuration
  上面介绍的是通过交互方式操作的一种办法。
  我们可以直接输入命令:
  "netsh interface ip add address "local area connection" 10.0.0.2 255.0.0.0"
  来添加 ip 地址。
  如果不知道语法,不要紧的哦!
  在提示符下,输入 ? 就可以找到答案了。方便不方便啊?
  原来微软的东西里面,也有那么一些让人喜欢的玩意儿。可惜,之至者甚少啊!
  windows网络命令行程序
  这部分包括:
  使用 ipconfig /all 查看配置
  使用 ipconfig /renew 刷新配置
  使用 ipconfig 管理 dns 和 dhcp 类别 id
  使用 ping 测试连接
  使用 arp 解决硬件地址问题
  使用 nbtstat 解决 netbios 名称问题
  使用 netstat 显示连接统计
  使用 tracert 跟踪网络连接
  使用 pathping 测试路由器
  使用 ipconfig /all 查看配置
  发现和解决 tcp/ip 网络问题时,先检查出现问题的计算机上的 tcp/ip 配置。可以使用 ipconfig 命令获得主机配置信息,包括 ip 地址、子网掩码和默认网关。
  注意
  对于 windows 95 和 windows 98 的客户机,请使用 winipcfg 命令而不是 ipconfig 命令。
  使用带 /all 选项的 ipconfig 命令时,将给出所有接口的详细配置报告,包括任何已配置的串行端口。  使用 ipconfig /all,可以将命令输出重定向到某个文件,并将输出粘贴到其他文档中。也可以用该输出确认网络上每台计算机的 tcp/ip 配置,或者进一步调查 tcp/ip 网络问题。
  例如,如果计算机配置的 ip 地址与现有的 ip 地址重复,则子网掩码显示为 0.0.0.0。
  下面的范例是 ipconfig /all 命令输出,该计算机配置成使用 dhcp 服务器动态配置tcp/ip,并使用wins 和 dns 服务器解析名称。
  windows 2000 ip configuration
  node type.. . . . . . . . : hybrid
  ip routing enabled.. . . . : no
  wins proxy enabled.. . . . : no
  ethernet adapter local area connection:
  host name.. . . . . . . . : corp1.microsoft.com
  dns servers . . . . . . . : 10.1.0.200
  description. . . . . . . : 3com 3c90x ethernet adapter
  physical address. . . . . : 00-60-08-3e-46-07
  dhcp enabled.. . . . . . . : yes
  autoconfiguration enabled.: yes
  ip address. . . . . . . . . : 192.168.0.112
  subnet mask. . . . . . . . : 255.255.0.0
  default gateway. . . . . . : 192.168.0.1
  dhcp server. . . . . . . . : 10.1.0.50
  primary wins server. . . . : 10.1.0.101
  secondary wins server. . . : 10.1.0.102
  lease obtained.. . . . . . : wednesday, september 02, 1998 10:32:13 am
  lease expires.. . . . . . : friday, september 18, 1998 10:32:13 am
 如果 tcp/ip 配置没有问题,下一步测试能够连接到 tcp/ip 网络上的其他主机。
  使用 ipconfig /renew 刷新配置
  解决 tcp/ip 网络问题时,先检查遇到问题的计算机上的 tcp/ip 配置。如果计算机启用 dhcp 并使用 dhcp 服务器获得配置,请使用 ipconfig /renew 命令开始刷新租约。
  使用 ipconfig /renew 时,使用 dhcp 的计算机上的所有网卡(除了那些手动配置的适配器)都尽量连接到dhcp 服务器,更新现有配置或者获得新配置。
  也可以使用带 /release 选项的 ipconfig 命令立即释放主机的当前 dhcp 配置。有关 dhcp 和租用过程的详细信息,请参阅客户机如何获得配置。
  注意
  对于启用 dhcp 的 windows 95 和 windows 98 客户,请使用 winipcfg 命令的 release 和 renew 选项,而不是 ipconfig /release 和 ipconfig /renew 命令,手动释放或更新客户的 ip 配置租约。
  使用 ipconfig 管理 dns 和 dhcp 类别 id
  也可以使用 ipconfig 命令:
  显示或重置 dns 缓存。
  详细信息,请参阅使用 ipconfig 查看或重置客户解析程序缓存。
  刷新已注册的 dns 名称。
  详细信息,请参阅使用 ipconfig 更新 dns 客户注册。
  显示适配器的 dhcp 类别 id。
  详细信息,请参阅显示客户机上的 dhcp 类别 id 信息。
  设置适配器的 dhcp 类别 id。
  详细信息,请参阅设置客户机上的 dhcp 类别 id 信息。
  使用 ping 测试连接
  ping 命令有助于验证 ip 级的连通性。发现和解决问题时,可以使用 ping 向目标主机名或 ip 地址发送 icmp 回应请求。需要验证主机能否连接到 tcp/ip 网络和网络资源时,请使用 ping。也可以使用 ping 隔离网络硬件问题和不兼容配置。
  通常最好先用 ping 命令验证本地计算机和网络主机之间的路由是否存在,以及要连接的网络主机的 ip 地址。ping 目标主机的ip 地址看它是否响应,如下:
  ping ip_address
  使用 ping 时应该执行以下步骤:
  ping 环回地址验证是否在本地计算机上安装 tcp/ip 以及配置是否正确。
  ping 127.0.0.1
  ping 本地计算机的 ip 地址验证是否正确地添加到网络。
  ping ip_address_of_local_host
  ping 默认网关的 ip 地址验证默认网关是否运行以及能否与本地网络上的本地主机通讯。
  ping ip_address_of_default_gateway
  ping 远程主机的 ip 地址验证能否通过路由器通讯。
  ping ip_address_of_remote_host
  ping 命令用 windows 套接字样式的名称解析将计算机名解析成 ip 地址,所以如果用地址成功,但是用名称 ping 失败,则问题出在地址或名称解析上,而不是网络连通性的问题。详细信息,请参阅使用 arp 解决硬件地址问题。
  如果在任何点上都无法成功地使用 ping,请确认:
  安装和配置 tcp/ip 之后重新启动计算机。
  “internet 协议 (tcp/ip) 属性”对话框“常规”选项卡上的本地计算机的 ip 地址有效而且正确。
  启用 ip 路由,并且路由器之间的链路是可用的。
  您可以使用 ping 命令的不同选项来指定要使用的数据包大小、要发送多少数据包、是否记录用过的路由、要使用的生存时间 (ttl) 值以及是否设置“不分段”标志。可以键入 ping -? 查看这些选项。
  下例说明如何向 ip 地址 172.16.48.10 发送两个 ping,每个都是 1,450 字节:
  c:\>ping -n 2 -l 1450 172.16.48.10
  pinging 172.16.48.10 with 1450 bytes of data:
  reply from 172.16.48.10:bytes=1450 time<10ms ttl=32
  reply from 172.16.48.10:bytes=1450 time<10ms ttl=32
  ping statistics for 157.59.8.1:
  packets:sent = 2, received = 2, lost = 0 (0% loss),
  approximate roundtrip times in milli-seconds:
  minimum = 0ms, maximum = 10ms, average = 2ms
  默认情况下,在显示“请求超时”之前,ping 等待 1,000 毫秒(1 秒)的时间让每个响应返回。如果通过 ping 探测的远程系统经过长时间延迟的链路,如卫星链路,则响应可能会花更长的时间才能返回。可以使用 -w (等待)选项指定更长时间的超时。
  使用 arp 解决硬件地址问题
  “地址解析协议 (arp)”允许主机查找同一物理网络上的主机的媒体访问控制地址,如果给出后者的 ip 地址。为使 arp 更加有效,每个计算机缓存 ip 到媒体访问控制地址映射消除重复的 arp 广播请求。
  可以使用 arp 命令查看和修改本地计算机上的 arp 表项。arp 命令对于查看 arp 缓存和解决地址解析问题非常有用。
  详细信息,请参阅查看“地址解析协议 (arp)”缓存和添加静态 arp 缓存项目。
  使用 nbtstat 解决 netbios 名称问题
  tcp/ip 上的 netbios (netbt) 将 netbios 名称解析成 ip 地址。tcp/ip 为 netbios 名称解析提供了很多选项,包括本地缓存搜索、wins 服务器查询、广播、dns 服务器查询以及 lmhosts 和主机文件搜索。
  nbtstat 是解决 netbios 名称解析问题的有用工具。可以使用nbtstat 命令删除或更正预加载的项目:
  nbtstat -n 显示由服务器或重定向器之类的程序在系统上本地注册的名称。
  nbtstat -c 显示 netbios 名称缓存,包含其他计算机的名称对地址映射。
  nbtstat -r 清除名称缓存,然后从 lmhosts 文件重新加载。
  nbtstat -rr 释放在 wins 服务器上注册的 netbios 名称,然后刷新它们的注册。
  nbtstat -a name 对 name 指定的计算机执行 netbios 适配器状态命令。适配器状态命令将返回计算机的本地 netbios 名称表,以及适配器的媒体访问控制地址。
  nbtstat -s 列出当前的 netbios 会话及其状态(包括统计),如下例所示:
  netbios connection table
  local name state in/out remote host input output
  ------------------------------------------------------------------
  corp1 <00> connected out corpsup1<20> 6mb 5mb
  corp1 <00> connected out corpprint<20> 108kb 116kb
  corp1 <00> connected out corpsrc1<20> 299kb 19kb
  corp1 <00> connected out corpemail1<20> 324kb 19kb
  corp1 <03> listening
  使用 netstat 显示连接统计
  可以使用 netstat 命令显示协议统计信息和当前的 tcp/ip 连接。netstat -a 命令将显示所有连接,而 netstat -r 显示路由表和活动连接。netstat -e 命令将显示ethernet 统计信息,而 netstat -s 显示每个协议的统计信息。如果使用 netstat -n,则不能将地址和端口号转换成名称。下面是 netstat 的输出示例:
  c:\>netstat -e
  interface statistics
  received sent
  bytes 3995837940 47224622
  unicast packets 120099 131015
  non-unicast packets 7579544 3823
  discards 0 0
  errors 0 0
  unknown protocols 363054211
  c:\>netstat -a
  active connections
  proto local address foreign address state
  tcp corp1:1572 172.16.48.10:nbsession established
  tcp corp1:1589 172.16.48.10:nbsession established
  tcp corp1:1606 172.16.105.245:nbsession established
  tcp corp1:1632 172.16.48.213:nbsession established
  tcp corp1:1659 172.16.48.169:nbsession established
  tcp corp1:1714 172.16.48.203:nbsession established
  tcp corp1:1719 172.16.48.36:nbsession established
  tcp corp1:1241 172.16.48.101:nbsession established
  udp corp1:1025 *:*
  udp corp1:snmp *:*
  udp corp1:nbname *:*
  udp corp1:nbdatagram *:*
  udp corp1:nbname *:*
  udp corp1:nbdatagram *:*
  c:\>netstat -s
  ip statistics
  packets received = 5378528
  received header errors = 738854
  received address errors = 23150
  datagrams forwarded = 0
  unknown protocols received = 0
  received packets discarded = 0
  received packets delivered = 4616524
  output requests = 132702
  routing discards = 157
  discarded output packets = 0
  output packet no route = 0
  reassembly required = 0
  reassembly successful = 0
  reassembly failures =
  datagrams successfully fragmented = 0
  datagrams failing fragmentation = 0
  fragments created = 0
  icmp statistics
  received sent
  messages 693 4
  errors 0 0
  destination unreachable 685 0
  time exceeded 0 0
  parameter problems 0 0
  source quenches 0 0
  redirects 0 0
  echoes 4 0
  echo replies 0 4
  timestamps 0 0
  timestamp replies 0 0
  address masks 0 0
  address mask replies 0 0
  tcp statistics
  active opens = 597
  passive opens = 135
  failed connection attempts = 107
  reset connections = 91
  current connections = 8
  segments received = 106770
  segments sent = 118431
  segments retransmitted = 461
  udp statistics
  datagrams received = 4157136
  no ports = 351928
  receive errors = 2
  datagrams sent = 13809
  使用 tracert 跟踪网络连接
  tracert(跟踪路由)是路由跟踪实用程序,用于确定 ip 数据报访问目标所采取的路径。tracert 命令用 ip 生存时间 (ttl) 字段和 icmp 错误消息来确定从一个主机到网络上其他主机的路由。
  tracert 工作原理
  通过向目标发送不同 ip 生存时间 (ttl) 值的“internet 控制消息协议 (icmp)”回应数据包,    tracert 诊断程序确定到目标所采取的路由。要求路径上的每个路由器在转发数据包之前至少将数据包上的 ttl 递减 1。数据包上的 ttl 减为 0 时,路由器应该将“icmp 已超时”的消息发回源系统。
  tracert 先发送 ttl 为 1 的回应数据包,并在随后的每次发送过程将 ttl 递增 1,直到目标响应或 ttl 达到最大值,从而确定路由。通过检查中间路由器发回的“icmp 已超时”的消息确定路由。某些路由器不经询问直接丢弃 ttl 过期的数据包,这在tracert 实用程序中看不到。
  tracert 命令按顺序打印出返回“icmp 已超时”消息的路径中的近端路由器接口列表。如果使用 -d 选项,则 tracert 实用程序不在每个 ip 地址上查询 dns。
  在下例中,数据包必须通过两个路由器(10.0.0.1 和 192.168.0.1)才能到达主机172.16.0.99。主机的默认网关是 10.0.0.1,192.168.0.0 网络上的路由器的 ip地址是 192.168.0.1。
  c:\>tracert 172.16.0.99 -d
  tracing route to 172.16.0.99 over a maximum of 30 hops
  1 2s 3s 2s 10,0.0,1
  2 75 ms 83 ms 88 ms 192.168.0.1
  3 73 ms 79 ms 93 ms 172.16.0.99
  trace complete.
  用 tracert 解决问题
  可以使用 tracert 命令确定数据包在网络上的停止位置。下例中,默认网关确定 192.168.10.99 主机没有有效路径。这可能是路由器配置的问题,或者是 192.168.10.0 网络不存在(错误的 ip 地址)。
  c:\>tracert 192.168.10.99
  tracing route to 192.168.10.99 over a maximum of 30 hops
  1 10.0.0.1 reportsestination net unreachable.
  trace complete.
  tracert 实用程序对于解决大网络问题非常有用,此时可以采取几条路径到达同一个点。
  tracert 命令行选项
  tracert 命令支持多种选项,如下表所示。
  tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name
  选项 描述
  -d 指定不将 ip 地址解析到主机名称。
  -h maximum_hops 指定跃点数以跟踪到称为 target_name 的主机的路由。
  -j host-list 指定 tracert 实用程序数据包所采用路径中的路由器接口列表。
  -w timeout 等待 timeout 为每次回复所指定的毫秒数。
  target_name 目标主机的名称或 ip地址。
  详细信息,请参阅使用 tracert 命令跟踪路径。
  使用 pathping 测试路由器
  pathping 命令是一个路由跟踪工具,它将 ping 和 tracert 命令的功能和这两个工具所不提供的其他信息结合起来。pathping 命令在一段时间内将数据包发送到到达最终目标的路径上的每个路由器,然后基于数据包的计算机结果从每个跃点返回。由于命令显示数据包在任何给定路由器或链接上丢失的程度,因此可以很容易地确定可能导致网络问题的路由器或链接。某些选项是可用的,如下表所示。
  选项 名称 功能
  -n hostnames 不将地址解析成主机名。
  -h maximum hops 搜索目标的最大跃点数。
  -g host-list 沿着路由列表释放源路由。
  -p period 在 ping 之间等待的毫秒数。
  -q num_queries 每个跃点的查询数。
  -w time-out 为每次回复所等待的毫秒数。
  -t layer 2 tag 将第 2 层优先级标记(例如,对于 ieee 802.1p)连接到数据包并将它发送到路径中的每个网络设备。这有助于标识没有正确配置第 2 层优先级的网络设备。-t 开关用于测试服务质量 (qos) 连通性。
  -r rsvp isbase che检查以确定路径中的每个路由器是否支持“资源保留协议 (rsvp)”,此协议允许主机为数据流保留一定量的带宽。 -r 开关用于测试服务质量 (qos) 连通性。
  默认的跃点数是 30,并且超时前的默认等待时间是 3 秒。默认时间是 250 毫秒,并且沿着路径对每个路由器进行查询的次数是 100。
  以下是典型的 pathping 报告。跃点列表后所编辑的统计信息表明在每个独立路由器上数据包丢失的情况。
  d:\>pathping -n msw
  tracing route to msw [7.54.1.196]
  over a maximum of 30 hops:
  0 172.16.87.35
  1 172.16.87.218
  2 192.68.52.1
  3 192.68.80.1
  4 7.54.247.14
  5 7.54.1.196
  computing statistics for 125 seconds...
  source to here this node/link
  hop rtt lost/sent = pct lost/sent = pct address
  0 172.16.87.35
  0/ 100 = 0%
  1 41ms 0/ 100 = 0% 0/ 100 = 0% 172.16.87.21813/ 100 = 13%
  2 22ms 16/ 100 = 16% 3/ 100 = 3% 192.68.52.10/ 100 = 0%
  3 24ms 13/ 100 = 13% 0/ 100 = 0% 192.68.80.1 0/ 100 = 0%
  4 21ms 14/ 100 = 14% 1/ 100 = 1% 10.54.247.14 0/ 100 = 0%
  5 24ms 13/ 100 = 13% 0/ 100 = 0% 10.54.1.196
  trace complete.
  当运行 pathping 时,在测试问题时首先查看路由的结果。此路径与 tracert 命令所显示的路径相同。然后 pathping 命令对下一个 125 毫秒显示忙消息(此时间根据跃点计数变化)。在此期间,pathping 从以前列出的所有路由器和它们之间的链接之间收集信息。在此期间结束时,它显示测试结果。
  最右边的两栏 this node/link lost/sent=pct 和 address 包含的信息最有用。172.16.87.218(跃点 1)和 192.68.52.1(跃点 2)丢失 13% 的数据包。 所有其他链接工作正常。在跃点 2 和 4 中的路由器也丢失寻址到它们的数据包(如 this node /link 栏中所示),但是该丢失不会影响转发的路径。
  对链接显示的丢失率(在最右边的栏中标记为 )表明沿路径转发丢失的数据包。该丢失表明链接阻塞。对路由器显示的丢失率(通过最右边栏中的 ip 地址显示)表明这些路由器的 cpu 可能超负荷运行。这些阻塞的路由器可能也是端对端问题的一个因素,尤其是在软件路由器转发数据包时。
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!