Azure VM-无法连接到侦听特定端口的TCP服务器 [英] Azure VM - Can't connect to a TCP server that listens on a specific port

查看:182
本文介绍了Azure VM-无法连接到侦听特定端口的TCP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在本地客户端和运行Windows 2K16的Azure VM(标准D1 v2)之间建立TCP连接.

I'm trying to establish a TCP connection between an on-prem client and an Azure VM (Standard D1 v2) running Windows 2K16.

在VM上,我正在运行一个接收端口的简单TCP服务器(请参见下面的代码).我已经在参数中传递了端口51515.

On the VM I'm running a simple TCP server (see code below) that receives the port. I've passes port 51515 in the arguments.

网络接口具有我要使用的公共IP.

The network interface have a public IP I'm trying to use.

我在门户网站的TCP端口51515上添加了入站端口规则(源=任何,源端口= *,目标=任何,目标端口= 51515,协议= TCP,操作=允许).

I've added an inbound port rule on TCP port 51515 on the portal (source=any, source port=*, destination=any, dest. port=51515, protocol=TCP, action=allow).

VM上的Windows防火墙已关闭(公用,域和专用).

Windows Firewall on the VM is off (public, domain and private).

我从本地使用Telnet,使用公共IP和51515端口.在此获取无法打开的连接消息.

I'm using Telnet from the on-prem side, using the public IP and the 51515 port. Getting the could not open connection message there.

我尝试访问VM上的IIS,并且可以使用另一个入站规则从本地访问IIS.

I've tried accessing the IIS on the VM and it is accessible from the on prem using another inbound rule.

有什么主意吗?

谢谢

汤姆

class Program
{
    static void Main(string[] args)
    {
        try
        {
            var server = new TcpListener(new IPEndPoint(IPAddress.Loopback, int.Parse(args[0])));
            server.AllowNatTraversal(true);
            server.Start();
            server.AcceptTcpClientAsync().ContinueWith(c => System.Console.WriteLine("Client connected from:" + c.Result.Client.RemoteEndPoint));
            System.Console.WriteLine("server listens... press any key to exit");
            System.Console.ReadKey();
        }
        catch (Exception e)
        {
            System.Console.WriteLine(e);
            System.Console.WriteLine("press any key to exit");
            System.Console.ReadKey();
        }
    }
}

推荐答案

正如EJP所说,IPAddress.Loopback表示127.0.0.1,该服务只能在VM内部访问.

As EJP said, IPAddress.Loopback means 127.0.0.1, the service only could access inside VM.

您需要在0.0.0.0或VM的专用ip上绑定端口.如下所示:

You need bind port on 0.0.0.0 or VM's private ip. Like below:

var server = new TcpListener(new IPEndPoint(IPAddress.Any, int.Parse(args[0])));

这篇关于Azure VM-无法连接到侦听特定端口的TCP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆