[asterisk-users] How to set externip in sip.conf automatically?

John Marvin jm-asterisk at themarvins.org
Wed Aug 23 13:52:12 MST 2006


Larry Alkoff wrote:
> As stated in the original post, when I entter the IP with an editor 
> directly into sip.conf calls work just fine but I am looking for a way 
> to have that done _automatically_.
> 
> The Asterisk - Future of Telephony book says it is possible for Asterisk 
> to access a Linux environment variable containing the IP information in 
> the form of "${ENV{variable}}.
> 
> It doesn't seem to work.  I am asking how to make it work.
> 

Actually, I don't think you read his response carefully enough. He was 
giving you a method of doing it automatically.

But first, lets dismiss the environment variable solution. I haven't 
played with using environment variables in Asterisk, so I can't help you 
there. But I do know about environment variables in general, and you 
cannot use them to solve your problem. Environment variables are not 
"global", i.e. if you change one it does not effect the value in all 
currently running programs. The "environment" (all of the environment 
variables and their values) is inherited from the parent process (it is 
passed in by the kernel on the new processes stack when the process 
first starts). After that, only the process itself can change its own 
values in order to pass on a changed value to a child (but again, only 
when that child process is started, i.e. a parent cannot affect the 
environment of an already running child process). In summary, you can't 
change the values of Asterisk's environment variables after Asterisk has 
already started. The values that Asterisk sees are the values that it 
inherited from its parent process, i.e. most likely the rc scripts that 
started Asterisk when you first booted the machine.

Now, back to the solution proposed by Brad. He was in effect proposing 
that you dynamically change sip.conf. However, parsing a rewriting 
sip.conf automatically is kind of ugly, but luckily Asterisk supports 
#include. So, he suggested that you can periodically generate a file 
with a single line in it, i.e. "externip=xx.xx.xx.xx" and then use 
#include in your sip.conf to include it (i.e. sip.conf doesn't have to 
ever change). The final part of the solution is to make Asterisk reread 
sip.conf (and the included dynamically created file at the same time). 
You can do that with:

	asterisk -rx "sip reload"

which you can put into the same cron job that you currently are using to 
refresh /etc/myip.

John



More information about the asterisk-users mailing list