Run coturn server with dynamic IP

Problem

Those of you who run coturn with a dynmic ip address will encounter a problem, that the ip address needs to be "hard coded" to the coturn config file. If your ip address changes every 24h, you can not write your ip to the config file. After spending some time to write a bash script to solve the problem, I will present the result here to you.

Solution

Follow the steps:

  1. Get the file coturn-dyn-ip.zip
  2. Upload myip.php to https://yourHomePage.com/myip.php
  3. Change #external-ip=60.70.80.91 to external-ip=60.70.80.91 in your coturn config turnserver.conf (do not care about the ip, it will be replaced later)
  4. Copy the file getIPchange.sh to /usr/local/bin/getIPchange.sh
  5. Make sure the file is writable by root only
  6. Make the script executable chmod +x /usr/local/bin/getIPchange.sh
  7. Add this line to your /etc/crontab:
    * * * * * root bash /usr/local/bin/getIPchange.sh
  8. Restart cron /etc/init.d/crond start

The bash script "getIPchange.sh" will detect ip changes. The script is triggered by cron every minute. In the case of an ip change, the new ip will be written to your coturn config file. If you don't have a provider where you can place the myip.php file, you can also use services like http://icanhazip.com/. Now you can enjoy your turn server by doing video chats in xmpp or nextcloud talk using your private turn.


imprint