通过 Azure CLI 使用 Azure 网络观察程序排查连接问题
了解如何使用排查连接问题来验证是否可以建立从虚拟机到给定终结点的直接 TCP 连接。
开始之前
本文假定你拥有以下资源:
- 要排查连接问题的区域中的网络观察程序实例。
- 用以排查连接问题的虚拟机。
重要
连接故障排除需要从中进行故障排除的 VM 安装了 AzureNetworkWatcherExtension
VM 扩展。 有关在 Windows VM 上安装扩展的信息,请访问适用于 Windows 的 Azure 网络观察程序代理虚拟机扩展;有关 Linux VM 的信息,请访问适用于 Linux 的 Azure 网络观察程序代理虚拟机扩展。 在目标终结点上不需要该扩展。
检查与虚拟机的连接
此示例通过端口 80 检查与目标虚拟机的连接。
示例
az network watcher test-connectivity --resource-group ContosoRG --source-resource MultiTierApp0 --dest-resource Database0 --dest-port 80
响应
以下响应来自前面的示例。 在此响应中,ConnectionStatus
为“不可访问” 。 可以看到所有探测都发送失败。 由于用户配置的名为 UserRule_Port80 的 NetworkSecurityRule
已配置为阻止端口 80 上的传入流量,虚拟设备上的连接失败。 可以使用此信息来了解连接问题。
{
"avgLatencyInMs": null,
"connectionStatus": "Unreachable",
"hops": [
{
"address": "10.1.1.4",
"id": "bb01d336-d881-4808-9fbc-72f091974d68",
"issues": [],
"nextHopIds": [
"f8b074e9-9980-496b-a35e-619f9bcbf648"
],
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/networkInterfaces/ap
pNic0/ipConfigurations/ipconfig1",
"type": "Source"
},
{
"address": "10.1.2.4",
"id": "f8b074e9-9980-496b-a35e-619f9bcbf648",
"issues": [],
"nextHopIds": [
"8a5857f3-6ab8-4b11-b9bf-a046d66b8696"
],
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/networkInterfaces/fw
Nic/ipConfigurations/ipconfig1",
"type": "VirtualAppliance"
},
{
"address": "10.1.3.4",
"id": "8a5857f3-6ab8-4b11-b9bf-a046d66b8696",
"issues": [
{
"context": [
{
"key": "RuleName",
"value": "UserRule_Port80"
}
],
"origin": "Outbound",
"severity": "Error",
"type": "NetworkSecurityRule"
}
],
"nextHopIds": [
"6ce2f7a2-ceb4-4145-80e8-5d9f661655d6"
],
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/networkInterfaces/au
Nic/ipConfigurations/ipconfig1",
"type": "VirtualAppliance"
},
{
"address": "10.1.4.4",
"id": "6ce2f7a2-ceb4-4145-80e8-5d9f661655d6",
"issues": [],
"nextHopIds": [],
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/networkInterfaces/db
Nic0/ipConfigurations/ipconfig1",
"type": "VnetLocal"
}
],
"maxLatencyInMs": null,
"minLatencyInMs": null,
"probesFailed": 100,
"probesSent": 100
}
验证路由问题
该示例检查虚拟机与远程终结点之间的连接。
示例
az network watcher test-connectivity --resource-group ContosoRG --source-resource MultiTierApp0 --dest-address 13.107.21.200 --dest-port 80
响应
在以下示例中,connectionStatus
显示为“不可访问” 。 在 hops
详细信息中,可以在 issues
下看到由于 UserDefinedRoute
流量已被阻止。
{
"avgLatencyInMs": null,
"connectionStatus": "Unreachable",
"hops": [
{
"address": "10.1.1.4",
"id": "f2cb1868-2049-4839-b8ed-57a480d06f95",
"issues": [
{
"context": [
{
"key": "RouteType",
"value": "User"
}
],
"origin": "Outbound",
"severity": "Error",
"type": "UserDefinedRoute"
}
],
"nextHopIds": [
"da4022db-0ab0-48c4-a507-dd4c03561ca5"
],
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/networkInterfaces/ap
pNic0/ipConfigurations/ipconfig1",
"type": "Source"
},
{
"address": "13.107.21.200",
"id": "da4022db-0ab0-48c4-a507-dd4c03561ca5",
"issues": [],
"nextHopIds": [],
"resourceId": "Unknown",
"type": "Destination"
}
],
"maxLatencyInMs": null,
"minLatencyInMs": null,
"probesFailed": 100,
"probesSent": 100
}
检查网站延迟
以下示例检查与网站的连接。
示例
az network watcher test-connectivity --resource-group ContosoRG --source-resource MultiTierApp0 --dest-address https://bing.com --dest-port 80
响应
在以下响应中,可以看到 connectionStatus
显示为“可以访问” 。 连接成功后,提供了延迟值。
{
"avgLatencyInMs": 2,
"connectionStatus": "Reachable",
"hops": [
{
"address": "10.1.1.4",
"id": "639c2d19-e163-4dfd-8737-5018dd1168ae",
"issues": [],
"nextHopIds": [
"fd43a6e7-c758-4f48-90aa-8db99105a4a3"
],
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/networkInterfaces/ap
pNic0/ipConfigurations/ipconfig1",
"type": "Source"
},
{
"address": "204.79.197.200",
"id": "fd43a6e7-c758-4f48-90aa-8db99105a4a3",
"issues": [],
"nextHopIds": [],
"resourceId": "Internet",
"type": "Internet"
}
],
"maxLatencyInMs": 7,
"minLatencyInMs": 0,
"probesFailed": 0,
"probesSent": 100
}
检查与存储终结点的连接
以下示例检查从虚拟机到博客存储帐户的连接。
示例
az network watcher test-connectivity --resource-group ContosoRG --source-resource MultiTierApp0 --dest-address https://contosoexamplesa.blob.core.chinacloudapi.cn/
响应
以下 json 是运行前面 cmdlet 的示例响应。 由于此检查成功,connectionStatus
属性显示为“可以访问” 。 提供了有关到达存储 Blob 所需的跃点数和延迟的详细信息。
{
"avgLatencyInMs": 1,
"connectionStatus": "Reachable",
"hops": [
{
"address": "10.1.1.4",
"id": "5136acff-bf26-4c93-9966-4edb7dd40353",
"issues": [],
"nextHopIds": [
"f8d958b7-3636-4d63-9441-602c1eb2fd56"
],
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/networkInterfaces/appNic0/ipConfigurations/ipconfig1",
"type": "Source"
},
{
"address": "1.2.3.4",
"id": "f8d958b7-3636-4d63-9441-602c1eb2fd56",
"issues": [],
"nextHopIds": [],
"resourceId": "Internet",
"type": "Internet"
}
],
"maxLatencyInMs": 7,
"minLatencyInMs": 0,
"probesFailed": 0,
"probesSent": 100
}
后续步骤
查看创建警报触发的数据包捕获,了解如何利用虚拟机警报自动执行数据包捕获
访问查看“IP 流验证”,了解是否允许某些流量传入和传出 VM