I found a way to use env var in kamailio.cfg. Here is a code to use MY_IP environment variable,

# 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

Best Regards,
Pavan Kumar


On Thu, May 2, 2024 at 10:21 AM Pavan Kumar <pavanputhra@gmail.com> wrote:
Thanks, I'll look into it. :) 

On Mon, Apr 29, 2024 at 12:03 PM Olle E. Johansson <oej@edvina.net> wrote:


On 28 Apr 2024, at 10:57, Pavan Kumar via sr-users <sr-users@lists.kamailio.org> wrote:

Hi everyone,

I am trying to assign environment variable as follows

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?

The config variables (called pseudo-variables in documentation) can only be used in the routing scripts, not in the core parameters section.

There is a way to add defines for substitution on the command line and use them though. Check the documentation in the core cookbook on how to use defines and the command line help for more information.

/O