# Need help regarding setting up turn server with mediasoup server

**URL:** <https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014>\
**Category:** Integration\
**Created:** [March 3, 2023, 12:13pm UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014 "2023-03-03T12:13:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![RagedPanda](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ragedpanda/32/2048_2.png) [@RagedPanda](https://mediasoup.discourse.group/u/RagedPanda)\
**Post date:** [March 3, 2023, 12:13pm UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/1 "2023-03-03T12:13:48Z")

</div>

Hi Team,

First of all, thank you for the Mediasoup, It’s amazing.  
I just need some help related to turn setup. I read IBC’s comment is one of the turn/stun setup post.

As per IBC :

> mediasoup (server) does not need any knowledge/configuration related to TURN. You must setup your TURN server so it has proper direct networking to the mediasoup server. That’s all.
> 
> In the client side you pass STUN/TURN servers when creating a send/recv transport:

I’m very new to this turn/stun. But as per the above comment, we put ice servers info in our client config and I saw we received packets in Coturn logs and the connection is also stated as a relay. I Just don’t know how we make a direct connection to our mediasoup server from the turn server?

Can anyone help me or share his approach to setting up the turn server to the mediasoup?

---

<div class="post-metadata">

**Author:** ![Bigcat](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@Bigcat](https://mediasoup.discourse.group/u/Bigcat)\
**Post date:** [March 3, 2023, 9:49pm UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/2 "2023-03-03T21:49:18Z")

</div>

Do you have STUN and TURN server URLs? if so, you just need to add the info to in the client side.

recvTransport = mediasoupDevice.createRecvTransport({ iceServers: [] )}

and you need to add IceServer to createSendTransport as well.  
You can find an example of how to the array format looks like

> **[RTCIceServers.urls - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer/urls)**
>
> The RTCIceServer dictionary's urls
> property specifies the URL or URLs of the servers to be used for ICE negotiations. These
> are typically STUN and/or TURN servers.

for security you may want to use proxy to save your TURN server credential

Always add stun and turn so in case stun does not work, you can rely your media over turn.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [March 4, 2023, 7:34am UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/3 "2023-03-04T07:34:25Z")

</div>

> [@Bigcat](#):
>
> Always add stun and turn so in case stun does not work, you can rely your media over turn.

Configuring a STUN server in a mediasoup-client is completely useless. mediasoup server is ICE Lite so it’s not gonna check client’s ICE candidates (which cannot even be signaled to mediasoup BTW). So this is incorrect.

Of course, you can configure a TURN server, but zero reasons to use a STUN server.

---

<div class="post-metadata">

**Author:** ![Bigcat](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@Bigcat](https://mediasoup.discourse.group/u/Bigcat)\
**Post date:** [March 4, 2023, 8:54pm UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/4 "2023-03-04T20:54:58Z")

</div>

@ibc Thank you for the info. I am coming from native Webrtc. good to know that stun is not needed. does that mean mediasoup-client will always try to avoid using TURN unless it was required? my concerned that TURN server will be used for ice candidates where TURN is not required.

I am wondering why the docs has “In the client side you pass STUN/TURN servers when creating a send/recv transport:” if mediasoup-client does not need it

---

<div class="post-metadata">

**Author:** ![RagedPanda](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ragedpanda/32/2048_2.png) [@RagedPanda](https://mediasoup.discourse.group/u/RagedPanda)\
**Post date:** [March 6, 2023, 3:37am UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/5 "2023-03-06T03:37:45Z")

</div>

Thanks, IBC for the info, but we need the Turn as we are inside a very strict firewall where we can’t expose too many open ports. So as a workaround, we need the Stun/Turn to listen on 443 and communicate with the Mediasoup server internally.

I just don’t understand or find anything related to configuring my Turn to have a direct connection with the Mediasoup server. I checked **turnserver.conf** file there I don’t find any field with the help of that we can achieve a direct connection. As you mentioned in your comment.

> You must setup your TURN server so it has proper direct networking to the mediasoup server.

Do you mean we have to put the Turn and the Mediasoup on the same server?

---

<div class="post-metadata">

**Author:** ![snnz](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/snnz/32/693_2.png) [@snnz](https://mediasoup.discourse.group/u/snnz)\
**Post date:** [March 6, 2023, 7:37am UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/6 "2023-03-06T07:37:02Z")

</div>

The client will send packets through the TURN server with the announced address of the mediasoup server as destination, mediasoup will see some address of the TURN server as the origin address. So you should make sure that there is a direct link between mediasoup’s external address and the address allocated by the TURN server for the client.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [March 6, 2023, 7:47am UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/7 "2023-03-06T07:47:59Z")

</div>

> [@RagedPanda](#):
>
> we need the Turn as we are inside a very strict firewall where we can’t expose too many open ports

You know there is WebRtcServer class in mediasoup which listen into a single port, right?

---

<div class="post-metadata">

**Author:** ![RagedPanda](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ragedpanda/32/2048_2.png) [@RagedPanda](https://mediasoup.discourse.group/u/RagedPanda)\
**Post date:** [March 6, 2023, 8:36am UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/8 "2023-03-06T08:36:57Z")

</div>

Right. Thanks for the comment, I’m actually forgetting about this thing. But now everything is clear.

Thanks again 😊

---

<div class="post-metadata">

**Author:** ![jsuryakt](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jsuryakt/32/2777_2.png) [@jsuryakt](https://mediasoup.discourse.group/u/jsuryakt)\
**Post date:** [September 11, 2025, 9:14am UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/9 "2025-09-11T09:14:50Z")

</div>

Yes, correct me if I’m wrong but if we want to run multiple WebRtcServers on different workers then we will still need TURN, to expose only 1 port.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [September 11, 2025, 9:31am UTC](https://mediasoup.discourse.group/t/need-help-regarding-setting-up-turn-server-with-mediasoup-server/5014/10 "2025-09-11T09:31:54Z")

</div>

That’s correct.
