kamailio

How to use environment variable in kamailio config file


I am trying to assign environment variable as follows in kamailio.conf

listen=udp:0.0.0.0:5060 advertise $env(MY_IP):5060

Looks like using the environment variable as above is an invalid configuration.

Is there a way to use IP from env var to advertise. Even better, is there a way to use result in a stun query as an advertised address?


Solution

  • Here is a code to use MY_IP environment variable value in config,

    # This will create MY_IP define with value from environment variable
    #!defenv MY_IP
    
    # MY_IP will be replaced with the value from MY_IP define
    listen=udp:0.0.0.0:5060 advertise MY_IP:5060
    

    To dynamically figure out ip address of the current machien one can use following command before starting kamailio

    export MY_IP=$(curl -s ifconfig.me)