Unable to connect to VM using public IP and custom port

GuyG-9858 1 Reputation point
2022-12-26T17:40:34.713+00:00

I am new to web socket development and I have a .Net Core custom web socket app running on an VM. I can run the app locally in the VM and connect using a simple JS client. I need the app to be accessible to our other apps using the VM public IP address. I have setup the Vnet and related subnets, when I run the Connection Troubleshoot on the vm, it says network connectivity allowed for the custom port 8085 (inbound and outbound). In the VM, I am running IIS and I have tried turning off the W3SVC service, I have setup firewall rules (inbound and outbound) for the Public network. TCP protocol, local port ANY, remote port ANY. No mater what I try, I get the following "Error: connect ETIMEDOUT [IP]:8085" when using Postman. If I temporarily disable the Firewall on the Public Network inside the VM, it comes back quickly with the following error "Unexpected server response: 400". My app logs connection attempts and all exceptions so if it was coming from the app I would have seen the exception thrown. I should also mention I'm using the System.Net.Httplistener class but it does work when I use my simple javascript from inside the VM. What else can I check to make this work?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Durkan 12,236 Reputation points MVP
    2022-12-26T18:56:28.633+00:00

    Hi

    you need to modify the NSG of the Virtual Network that the VM is attached to in order to allow specific traffic. There are only certain ports enabled by default, and you can then add the ones you require. More details here:

    https://learn.microsoft.com/en-us/azure/virtual-network/network-security-groups-overview

    Hope this helps,

    Thanks

    Michael Durkan

    • If the reply was helpful please upvote and/or accept as answer as this helps others in the community with similar questions. Thanks!
    0 comments No comments

  2. GuyG-9858 1 Reputation point
    2022-12-26T21:01:09.057+00:00

    Thank you Michael, my NSG is already configured with the desired port (8085) for inbound and outbound. I did notice the bit about Azure converting from public IP to private on inbound and vice versa on outbound. Updated my rules accordingly and still no change in my results.

    0 comments No comments

  3. dkrishnaveni-MSFT 1,961 Reputation points Microsoft Employee
    2022-12-27T04:48:05.563+00:00

    Hi,

    Can you open a cmd promt and type in "netstat -ano" and check if the port 8085 is listening?

    Can you share me the screenshot of the 400 response ?

    Regards,
    Divya

    0 comments No comments

  4. GuyG-9858 1 Reputation point
    2022-12-27T12:45:23.213+00:00

    274239-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.