Azure VMs not able to talk to STUN server for WebRTC

Naval Rishi 20 Reputation points
2025-05-18T05:10:49.69+00:00

I have a VM that I'm trying to use to with a webRTC application but it's not able to talk to any STUN servers to get ICE candidates. I'm using this for testing. This works on my personal machine on my Wifi and even on my phone on mobile data but doesn't work for any VMs.
https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
The VM has a public IP, no outbound traffic restriction, no extra firewall in the NSG, all default settings, but I can't figure out why the request fails. I tried self troubleshooting from Azure and it gives a green tick for all services but the connectivity check fails.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,041 questions
{count} votes

Accepted answer
  1. Nikhil Duserla 8,100 Reputation points Microsoft External Staff Moderator
    2025-05-23T10:49:10.4733333+00:00

    Hello @Naval Rishi,

    Navigate to RDP application and mark the settings. Navigate to local resources>>In local resources and resources click more and choose the devices in below.User's image

    try test again once marked the devices.

    User's image

    If you have any further queries, do let us know.

    If you found this informative, please consider accepting an answer as a token of appreciation. And don't forget to give it a thumbs up 👍 if it was helpful.

    User's image

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Alex Burlachenko 10,335 Reputation points
    2025-05-20T08:16:56.2166667+00:00

    Hi Naval Rishi,

    thank you for posting your question on the Q&A portal and providing those details about your issue with Azure Virtual Machines and WebRTC. It’s definitely frustrating when something works locally but not in the cloud, so let’s try to break this down step by step.

    First, since your VM has a public IP and no outbound restrictions in the Network Security Group (NSG), the basics seem correct. But there are a few Azure-specific things that could be blocking STUN traffic. WebRTC relies on STUN servers to discover ICE candidates, and if the VM can’t reach them, it’s often a networking or configuration issue.

    One common gotcha is that Azure’s default NSG rules allow outbound traffic, but some ISPs or intermediate firewalls might block UDP ports used by STUN (usually 3478 and 5349). Even though your NSG is open, Azure’s underlying infrastructure or your VM’s local firewall could interfere. You can check the local firewall on the VM to ensure it’s not blocking these ports. Here’s Microsoft’s documentation on NSG rules for reference: Network Security Groups in Azure.

    Another thing to test is whether your VM can reach the STUN server at all. Try running a simple UDP connectivity test using tools like nc (netcat) or Test-NetConnection in PowerShell. For example, if you’re using stun.l.google.com:19302, you could check if the VM can send/receive UDP packets to that endpoint. If it fails, it might be a routing issue. Azure sometimes applies platform-level filters, so you might need to explicitly allow UDP traffic in the NSG, even if it seems open.

    Also, double-check that the VM’s public IP is properly associated and not stuck in a "middle" state. Sometimes, restarting the VM or reassigning the IP can help. Here’s more info on public IPs in Azure: Public IP addresses in Azure.

    Lastly, if you’re using a custom DNS or have modified the VM’s network settings, ensure DNS resolution works for the STUN server’s domain. You can test this with nslookup stun.l.google.com from the VM.

    If none of this helps, could you share the exact error or behavior you’re seeing? For example, does the request time out, or is there a specific error in the browser console? That might give more clues.

    Hope this points you in the right direction! Let me know if you hit any snags, and I’ll try to help further.

    Best regards,
    Alex
    P.S. If my answer help to you, please Accept my answer
    PPS That is my Answer and not a Comment
    https://ctrlaltdel.blog/
    
    Best regards,
    Alex
    P.S. If my answer help to you, please Accept my answer
    PPS That is my Answer and not a Comment
    https://ctrlaltdel.blog/
    
    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.