External address in the "Сontact" field of the REGISTER SIP-frame

Colleagues, tell me please how can I solve my problem!

My asterisk is behind NAT and has an intranet address.
On the main router, a number of ports are forwarded to asterisk, to receive incoming connections via SIP and RTP.
One of their providers requires the registration of sip-accounts.
The “Contact:” field of SIP-frames “REGISTER” contains a URI with an internal intranet address.

How can I change the URI in the “Contact:” field in SIP-frame “REGISTER”? For example, instead of "1234567@" enter there “1234567@my_extern_address”?

I use Asterisk 13.14.0 on FreeBSD 10.3 amd64.

Thankful in advance,

You would need to configure the respective SIP channel driver (chan_sip or chan_pjsip) to know it is behind NAT. Which channel driver are you using?

I’m using chan_sip.
The problem that prompted me to ask this question, I decided. I created the ‘externip’ and ‘localnet’ entries in sip.conf [global].
Nevertheless, I am very grateful to you for having responded to my question.

However, understanding this method gives me two more questions.
1. If my server started using a different ip-address, can I switch the value ‘externip’ on the fly?
2. If my server has several interfaces with nat, is it possible to associate with each of them its own value of ‘externip’?


  1. I’m not aware of one, but but it is possible that one has been added, however, you do not have an adequate internet access service for running any server if the IP address is not stable.

  2. No, If you a multi-homed, Asterisk requires that you do it properly, with static addresses, border gateway protocol and an autonomous system number. In that way, it doesn’t matter which IP address is used; they will all find their way to the nearest interface.

I believe that you did not understand me correctly.
This is not a dynamic IP address.

I meant that the server is connected to two different providers. Each has its own address pool.
If one provider fails, the default routing switches to the other. In this case, it is not possible to get an autonomous system and connect to providers with dynamic routing protocols.


I had in mind a slightly different case.
The server is connected to the provider and work with sip-operators through it.
However, another operator allows access only through its core network. It is connected to a separate interface and uses its intranet addresses.

The address provided by the main provider I can describe in ‘externip’ and everything will be fine.
But what should I do with a separate operator interface?

Asterisk only supports internet use with some tolerance of a single private network.

If the provider doesn’t want to allow internet access, you will typically need to use two instances of Asterisk, with something other than SIP used to interconnect them.