Configure turn server for WebRTC on Amazon EC2

Table of contents
Reading Time: 2 minutes

As we all know, WebRTC is used for video communication.
In video communication, data packets are transferred from one place to another place, therefore a user is able to see other user’s streaming.

But sometimes, when there are some network securities like firewall, then data packet does not transfer and we do not get proper streaming of another user i.e. we get black screen as other user’s stream.

So for this solution, we use turn server.

The TURN Server is a VoIP media traffic NAT traversal server and gateway. It can be used as a general-purpose network traffic TURN server and gateway, too.

Here, I am going to explain you the steps of installing and configuring turn server on Amazon EC2.

First of all download these 2 packages :
libevent-2.0.21-stable.tar.gz (
turnserver- (

then run these commands :
1. To install libevent package
$ tar xvfz libevent-2.0.21-stable.tar.gz
$ cd libevent-2.0.21-stable
$ ./configure
$ make
$ sudo make install

2. To install turn server
$ tar xvfz turnserver-
$ cd turnserver-
$ ./configure
$ make
$ sudo make install

3. $ ldconfig
Idconfig command to create, update, and remove the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/, and in the trusted directories (/usr/lib, /lib64 and /lib).

4. In your Javascript code where the RTCPeerConnection is created, reference the TURN server as follows:
var pc_config = {“iceServers”: [{“url”: “”}, {“url”:”turn:my_username@’amazon ec2 PUBLIC ip address’ “, “credential”:”my_password”}]};
pc_new = new webkitRTCPeerConnection(pc_config);

5. Open the following ports:
TCP 443
TCP 3478-3479
TCP 32355-65535
UDP 3478-3479
UDP 32355-65535

6. then run this command from turnserver- folder to start the turn server
$ sudo turnserver –syslog -a -L ‘amazon ec2 PRIVATE ip address’ -X ‘amazon ec2 PUBLIC ip address’ -E ‘amazon ec2 PRIVATE ip address’ -f –min-port=32355 –max-port=65535 –user=’my_username’:’my_password’ -r realm –log-file=stdout -v

Written by 

Rishi is a tech enthusiast with having around 10 years of experience who loves to solve complex problems with pure quality. He is a functional programmer and loves to learn new trending technologies. His leadership skill is well prooven and has delivered multiple distributed applications with high scalability and availability by keeping the Reactive principles in mind. He is well versed with Scala, Akka, Akka HTTP, Akka Streams, Java8, Reactive principles, Microservice architecture, Async programming, functional programming, distributed systems, AWS, docker.

43 thoughts on “Configure turn server for WebRTC on Amazon EC22 min read

  1. Hi,

    I am trying to do the same, however running into some problems. Firstly, what do you mean by the amazon ec2 PUBLIC/PRIVATE ip address ? I believe my amazon ec2 isnt behind any NAT per se given i can directly ssh into it. How do I go about knowing the private address ?

    Also, whats the use of the username/password/realm ?

    Thanks a ton

    1. Hi Harry

      For Public/Private IP address: Just go to Amazon EC2 instance -> Select the instance and then you will get all the information of that instance below. Then you will get there Public IPs and Private IPs section.

      Username/password : As you will see that whatever the username and password we are giving in command , the same we are providing in JavaScript in step 4.. So to authenticate user, we provide these values.

  2. Hi,
    Iam trying to run the turnserver on AMAZON EC2 instance but it says ..
    UDP/DTLS listener opened on:
    but its not the public ip its private ip .
    Is it work even though it displays that message i did all you said above no errors and warnings

  3. hi, following the instructions everything seems to work. But the remote video appears as a black square.

    Looking at the logs on turn server, we can see this result:

    2291: handle_udp_packet: New UDP endpoint: local addr, remote addr
    2291: user : incoming packet BINDING processed, success
    2292: user : incoming packet BINDING processed, success
    2292: handle_udp_packet: New UDP endpoint: local addr, remote addr
    2292: user : incoming packet BINDING processed, success
    2292: user : incoming packet BINDING processed, success
    2292: user : incoming packet BINDING processed, success

    some ideas?

    thanks in advance

  4. hi, when running step number 6, does the IP’S username and password need to be between quotation marks? ‘xxx-xxx-xxx-xxx’

    1. sudo turnserver -syslog -a -L ‘xx.xx.xx.xx’ -X ‘yy.yy.yy.yy’ -E ‘xx.xx.xx.xx’ -f –min-port=32355 –max-port=65535 –user=’userName’:’password’ –realm –log-file=stdout -v –max-bps=20000 –no-stun

  5. give as it is and replace xx.xx.xx.xx and yy.yy.yy.yy read documentation for better understanding and to test check calls between 2 countries or any secured network or restricted access location

    ….. Hope this helps

  6. i need to mention that yy.yy.yy.yy is public ip address
    xx.xx.xx.xx is your private not local this is exist only when u r under NAT or AWS EC2

  7. Wheb you say username and password, do you mean we need to configure an account in the turbuserdb.conf file ? Or are we using the aws credentials ?

    1. sudo turnserver -syslog -a -L ‘xx.xx.xx.xx’ -X ‘yy.yy.yy.yy’ -E ‘xx.xx.xx.xx’ -f –min-port=32355 –max-port=65535 –user=’userName’:’password’ –realm –log-file=stdout -v –max-bps=20000 –no-stun

      the above command itself says USERNAME and PASSWORD

  8. Great Article, but what is the -r realm? is realm the value we should pass or do we make it up? does aws provide this value? the docs around it are confusing. do you have any examples?

    1. When you will read “README.turnserver” file inside the turnserver package, then you will find the explanation for the same.
      It says :
      “Realm to be used for all users. Must be used with long-term credentials mechanism or with TURN REST API.”

      1. ok Thank you, I got it to work! one remark, I believe that “–min-rt=32355” is misspelled and should be “–min-port=32355”. most people probably figure it out, but it is a pretty crucial step for the tutorial.

  9. I asked before, but I am not sure the comment posted. anyways, What should the realm value be? where do I get this value, or should I literally just pass the word realm?


  10. Can you explain each parameter in this line {“url”:”turn:my_username@’amazon ec2 PUBLIC ip address’ “, “credential”:”my_password”} ? I am struck and do not know how to move forward.

    1. For my_username and my_password : These are the values which we are passing in step 6. These 2 should be same.
      amazon ec2 PUBLIC ip address : this is your amazon EC2’s public IP address

      1. Thank You Sir. Can you help me accessing RTC from two different networks? I am running a browser client app and an Android app where both the are connected in the same network. It works fine.
        When change browser and Android app to different networks they do not work. I do not know how use my Amazon Turn server to rectify this problem. Please help me.

  11. Hi,
    This is a great article. It was a great help but I wanted to know what are the minimum configuration(ram,cpu) required to run the turn server?.. I want my turn server to handle 20 concurrent audio only webrtc calls.

  12. Do I need to do anything with /etc/turnserver.conf file before following your steps? I have been struggling to get your steps done. Please guide me.

  13. Hello,

    Thank you very much for simplification of TURN server installation.

    I have started my TURN server on EC2. And my Node.js server for WebRTC is also on same instance. When I am trying to make call from Wifi, it’s getting connected but when I am trying from 4G or 3G network it’s showing black screen.

    I red some of your solutions and tried as well but non of them helped. Tell me one more thing how you made your EC2 instance as public as you mentioned here in this link ( Link:


    1. Hi Sachin,

      First thing, As you mentioned above, I have not mentioned anything in the given link: This link does not belong to me.

      Second, If you are talking about public IP pf EC2, then note one thing we don’t make the instances as public. EC2 instance contains 2 IPs by its own, public and private. So As i read in the given link, it is talking about public IP of ec2 instance.

      1. Hi Rishi,

        I agree that, the link which I mentioned does not belongs to you, but I was trying to give an context of my problem. sorry for it.
        But I am facing similar kind of problem.

        I am aware about Public and Private IP of my EC2 instance. but if you read this answer (Link: you will get to know why I get confused about making instance public.

        Can you please ping me on my gmail id?


  14. if we are using this turnserver guaded by above then we dont need to pay any cost. Means on our amazon instance we can install turnserver. Also there is any space matter if more user calling at the same time, means bandwidth issue etc

  15. CONFIGURATION ALERT Unknown argument: – ;;
    this error is coming when i run the above command

  16. Hi Rishi,
    We are using turnserver version, but your command of turnserver doesn’t work. there is error reads not known command ––max-port=65535, and our local can’t reach AWS EC2 container, could you please help? we are using port 80 instead of 3478.

Comments are closed.