问题描述

在使用 Azure App Service(Windows 和 Linux)部署应用时,如何分析网络连接情况,尤其是查看特定端口(如 443, 3306, 6380等)的连接状态?这对于排查连接异常、验证服务是否正常监听端口、确认后端服务是否建立连接等场景非常关键。

在本地环境中,可以使用netstat命令来查看网络连接状态。但是,在App Service 云环境中,是否还可以使用netstat命令呢?

netstat 是一个用于显示网络连接、路由表、接口状态等信息的命令行工具。它可用于诊断网络问题,查看端口是否被监听、连接是否建立,以及对应的进程信息。适用于 Windows 和 Linux 系统。

问题解答

可以使用 netstat 命令在 App Service 的容器或Linux实例中查看端口连接情况, 但是在Windows环境中被禁用。

在 Linux App Service 中:

使用如下命令:

netstat -anp | grep 443
  • -a:显示所有连接和监听端口。
  • -n:以数字形式显示地址和端口。
  • -p:显示关联的进程 ID 和名称。
  • grep 443:过滤出使用 443 端口的连接。

如图所示,输出结果中显示多个 TCP 连接,状态为 ESTABLISHED,说明这些连接已成功建立,且由进程 329/java 处理。

在 Windows App Service 中:

在Kudu的CMD中使用命令:netstat -ano | findstr 443

或者在Powershell中使用命令:Get-NetTCPConnection -LocalPort 443

都是Access is Denied。两个指令都被禁用了。

所以App Service for Windows 环境中,没有直接的方式可以查看到当前的网络连接情况。只有通过App Service 指标Connections来进行辅助判断。

PS: App Service for Windows 可以通过门户上抓取网络包,这样可以更全面的分析网络状态。

页面导航:App Service 门户 --> Networking页面 -->页面上的“Troubleshoot” 按钮 --> Collect Network Trace

附录

Window环境中netstat命令说明

C:\>netstat -help

Displays protocol statistics and current TCP/IP network connections.

NETSTAT [-a] [-b] [-e] [-f] [-i] [-n] [-o] [-p proto] [-r] [-s] [-t] [-x] [-y] [interval]

  -a            Displays all connections and listening ports.
-b Displays the executable involved in creating each connection or
listening port. In some cases well-known executables host
multiple independent components, and in these cases the
sequence of components involved in creating the connection
or listening port is displayed. In this case the executable
name is in [] at the bottom, on top is the component it called,
and so forth until TCP/IP was reached. Note that this option
can be time-consuming and will fail unless you have sufficient
permissions.
-c Displays a list of processes sorted by the number of TCP or UDP
ports currently consumed.
-d Displays DSCP value assocated with each connection.
-e Displays Ethernet statistics. This may be combined with the -s
option.
-f Displays Fully Qualified Domain Names (FQDN) for foreign
addresses.
-i Displays the time spent by a TCP connection in its current state.
-n Displays addresses and port numbers in numerical form.
-o Displays the owning process ID associated with each connection.
-p proto Shows connections for the protocol specified by proto; proto
may be any of: TCP, UDP, TCPv6, or UDPv6. If used with the -s
option to display per-protocol statistics, proto may be any of:
IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.
-q Displays all connections, listening ports, and bound
nonlistening TCP ports. Bound nonlistening ports may or may not
be associated with an active connection.
-r Displays the routing table.
-s Displays per-protocol statistics. By default, statistics are
shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6;
the -p option may be used to specify a subset of the default.
-t Displays the current connection offload state.
-x Displays NetworkDirect connections, listeners, and shared
endpoints.
-y Displays the TCP connection template for all connections.
Cannot be combined with the other options.
interval Redisplays selected statistics, pausing interval seconds
between each display. Press CTRL+C to stop redisplaying
statistics. If omitted, netstat will print the current
configuration information once.

Linux环境中netstat命令说明

eae863e36bd8:/# netstat -h
netstat: unrecognized option: h
BusyBox v1.36.1 (2024-06-10 07:11:47 UTC) multi-call binary. Usage: netstat [-ral] [-tuwx] [-enWp] Display networking information -r Routing table
-a All sockets
-l Listening sockets
Else: connected sockets
-t TCP sockets
-u UDP sockets
-w Raw sockets
-x Unix sockets
Else: all socket types
-e Other/more information
-n Don't resolve names
-W Wide display
-p Show PID/program name for sockets

【END】

【App Service】在Azure环境中如何查看App Service实例当前的网络连接情况呢?的更多相关文章

  1. 【Azure 应用服务】PHP应用部署在App Service for Linux环境中,上传文件大于1MB时,遇见了413 Request Entity Too Large 错误的解决方法

    问题描述 在PHP项目部署在App Service后,上传文件如果大于1MB就会遇见 413 Request Entity Too Large 的问题. 问题解决 目前这个问题,首先需要分析应用所在的 ...

  2. ASP.NET 在 Windows Azure 环境中使用基于 SQLServer 的 Session

    Session 嘛,占一点儿服务器资源,但是总归比 ViewState 和 Cookie 安全点儿,所以还是要用的. Windows Azure 环境中的 Web 服务器经由负载均衡调度,根本无法保证 ...

  3. 【转】Linux下查看TCP网络连接情况

    查看TCP网络连接情况 命令:netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’ www.2cto.com 返回结 ...

  4. Linux网络——查看网络连接情况的命令

    Linux网络——查看网络连接情况的命令 摘要:本文主要学习了Linux中用来查看网络连接情况的命令. hostname命令 hostname命令用于显示和设置系统的主机名称,设置只是临时生效,永久生 ...

  5. Azure环境中Nginx高可用性和部署架构设计

    前几篇文章介绍了Nginx的应用.动态路由.配置.在实际生产环境部署时,我们需要同时考虑Nginx的高可用性和部署架构. Nginx自身不支持集群以保证自身的高可用性,商业版本的Nginx+推荐: T ...

  6. linux系统查看网络连接情况

    netstat命令状态说明: CLOSED                      没有使用这个套接字[netstat 无法显示closed状态] LISTEN 套接字正在监听连接[调用listen ...

  7. 【Azure 应用服务】App Service For Windows 环境中部署Python站点后,如何继续访问静态资源文件呢(Serving Static Files)?

    问题描述 当创建一个App Service 后,运行时环境和版本选择Windows 和 Python 3.6. 登录Kudu 站点查看,默认的文件有 web.config, hostingstart- ...

  8. linux环境中,如何查看某个软件包,都依赖哪些软件包?被哪些软件包依赖?

    需求描述: 今天查看主机上的一个软件ghostscript,准备删除,就先看下这个软件都依赖哪些软件, 然后呢被哪些软件依赖 操作过程: 1.查看这个软件依赖哪些软件(rpm方式查询) [root@t ...

  9. linux中 查看 CPU 内存负载 磁盘IO 网络IO情况

    1.压测时如何观察机器的CPU负载 先来看一个最最常用的监测linux机器性能的命令,就是top命令,直接在linux命令行只能够输入top指令就可以了,然后我们这里来给大家解释一下,top指令展示出 ...

  10. 万答#21,如何查看 MySQL 数据库一段时间内的连接情况

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 查看方式 已知至少有两种方式可以实现 1.开启 general_log 就可以观察到 开启命令 mysql> set ...

随机推荐

  1. Windows Server 2025激活教程

    Windows Server 如何把评估版升级改为正式版本并激活 微软官方并不提供server系统的正式版本,只提供测试的评估版本,那么我们怎么修改为正式版本呢? 1.确认版本 开始----运行--- ...

  2. .net一般应用处理程序

    .net一般应用处理程序 public void ProcessRequest (HttpContext context) { context.Response.ContentType = " ...

  3. Luogu P10507 Georgia and Bob 题解

    P10507 Georgia and Bob 这篇题解的注重点不是结论的证明,而是发现结论的思路,所以比较偏感性.证明人人都会,而发现结论的思路才是这题真正值得思考的地方. 感觉这道题不知道阶梯 NI ...

  4. 认识Android Studio中各个模块

    首先看看刚创建完的项目界面,除了菜单栏.工具栏等,没有什么可以编辑的界面   通过项目的文件浏览器可以打开所有项目文件,所以文件管理器在整个开发过程中相当重要. 其中用到最多的便是app项,其余大部分 ...

  5. java 生产者消费者模式 使用标志位进行判断

    简介 RT code package com.kuang; /** * Created by lee on 2021/3/30. */ public class TestPC2 { public st ...

  6. vue 学习视频推荐 & 初始化项目流程

    简介 vue 有些名词听着很牛逼 vue-路由 啥的就是 标签的不再刷新的版本.其实选一个比较好的入门的视频挺好的. bilibili link https://www.bilibili.com/vi ...

  7. MCP快速入门—快速构建自己的服务器

    引言 随着大语言模型(LLM)技术的快速发展,如何扩展其能力边界成为开发者关注的重点.MCP(Model Capability Protocol)作为一种协议标准,允许开发者构建自定义服务器来增强LL ...

  8. Scrcpy Shortcuts

    Actions can be performed on the scrcpy window using keyboard and mouse shortcuts. In the following l ...

  9. .NET周刊【7月第2期 2025-07-13】

    国内文章 .Net 下高性能 Socket 的方案 https://zhuanlan.zhihu.com/p/1924520585976849438 简单介绍Socket的数据组成.详细介绍.Net高 ...

  10. 突破WAF!帆软模板注入漏洞利用新姿势

    前言 24年9月份的时候打攻防遇到一个帆软报表版本为v11,从/webroot/decision/system/info可以看到细的版本号为模版注入修复前的版本.于是直接使用/webroot/deci ...