当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 通过 PowerShell 解决 Windows Server 网络连接问题

作者:精品下载站 日期:2024-12-14 19:04:30 浏览:16 分类:玩电脑

通过 PowerShell 解决 Windows Server 网络连接问题


Windows Server 为管理员提供了大量工具,以防应用程序或计算机无法连接到特定端口或服务器 IP。立即弹出的一件事是使用工具来解决 DNS 和其他网络问题,但如果您喜欢使用 PowerShell,则可以使用一个出色的命令 Test-NetConnection

[玩转系统] 通过 PowerShell 解决 Windows Server 网络连接问题

通过 PowerShell 解决网络连接问题

您可以使用 Test-NetConnection cmdlet 查找连接的诊断信息。它包括对 Ping 测试、TCP 测试、路由跟踪以及路由选择诊断的支持。

根据使用的选项,输出将包含计算机名称、远程地址、SelectedSourceAddress、OutgoingInterfaceIndex、SelectedNetRoute 等信息。

这是支持的参数列表

  • CommonTCPPort:指定典型服务TCP端口号

  • ComputerName:指定目标计算机的域名系统 (DNS) 名称或 IP 地址。

  • ConstrainInterface:指定用于路由诊断的接口约束。

  • ConstrainSourceAddress:指定用于路由诊断的源地址约束。

  • DiagnoseRouting:表示运行路由诊断以输出远程主机的路由和源地址选择信息。

  • Hops:指定traceroute 命令中要遍历的跳数。

  • InformationLevel:指定信息级别详细或安静

  • 端口:指定远程计算机上的 TCP 端口号。

  • TraceRoute:表示运行 Tracert 以测试与远程主机的连接。

使用强大的Test-NetConnection cmdlet

Test-NetConnection -ComputerName "www.contoso.com" -ConstrainInterface 5 -DiagnoseRouting -InformationLevel "Detailed"

ComputerName : www.contoso.com

RemoteAddress : 2600:1409:a:185::2768

ConstrainInterfaceIndex : 5

SelectedSourceAddress : 2001:4898:e0:79:75dd:64cf:d9ff:f86

OutgoingInterfaceIndex : 5

SelectedNetRoute : DestinationPrefix: ::/0

NextHop: fe80::200:5eff:fe00:202

RouteSelectionEvents : IP: Route [DestinationPrefix: ::/0 NextHop: fe80::200:5eff:fe00:202 InterfaceIndex: 4

RouteMetric: 256] is blocked for Destination: 2600:1409:a:185::2768 ConstrainInterfaceIndex: 5 ConstrainScopeZone: 1 in Compartment: 1, Reason: InterfaceConstraint.

SourceAddressSelectionEvents : IP: Source address 2001:4898:e0:79:75dd:64cf:d9ff:f86 is preferred over fe80::75dd:64cf:d9ff:f86 for destination 2600:1409:a:185::2768 Rule = 2.0.

IP: Source address 2001:4898:e0:79:75dd:64cf:d9ff:f86 is preferred over fe80::75dd:64cf:d9ff:f86 for destination 2600:1409:a:185::2768 Rule = 2.0.

RouteDiagnosticsSucceeded : True

示例命令列表

[玩转系统] 通过 PowerShell 解决 Windows Server 网络连接问题

以下是一些您可以在计算机上尝试的示例命令。其中一些命令需要管理员权限,因此请确保使用所需权限启动 PowerShell 7 或 PowerShell 5.1。

Test-NetConnection youtube.com

有关连接的更多详细信息:

Test-NetConnection youtube.com -InformationLevel "Detailed"

当使用Web服务时,它是测试特定的TCP端口。

Test-NetConnection youtube.com -Port 443 -InformationLevel "Detailed"

执行路由诊断以连接到远程主机。

Test-NetConnection -ComputerName itopstalk.com -DiagnoseRouting -InformationLevel Detailed

查找网站的默认端口

Test-NetConnection -ComputerName microsoft.com -CommonTCPPort HTTP

为网站运行跟踪路由

Test-NetConnection -ComputerName google.com -TraceRoute

也就是说,如果您在非 Windows 平台上但使用与 Windows 中相同的命令,这会很有帮助。

除此之外,我还注意到对某些网站(例如 Microsoft.com)执行命令。这不起作用。 Ping 始终失败,这可能是服务器阻止了此类随机请求。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯