How can I set two IP address for one sip peer

[size=150]I have a sip peer as a sip trunk in Asterisk. The sip provider gives me two ip address, for redundancy. Can I set two IP address for one sip peer and automatically change to another when the primary one is down?


I’m not sure but, maybe you have to set Secondary IP on one interface

You can make 2 sip peers with 1 IP each if them - both can terminate in same place.

If I set 2 sip peers for Asterisk, and I always use the first one to place calls. When the first peer is down, how can I know about this and automatically use second peer to place calls?


Check dial command - you can dial 2 or more “numbers” simultaneously and first (who answer) will take a call.
I am not sure this will work as you want - you just need to check.
Of course you can check line first - using ping or something alike and then dial …

yes, dial command can dial 2 numbers simultaneously.

what if both 2 ip address are working.
Then I will place 2 calls to one number at the same time.
I don’t think this is the solution.

Can I check the variable “DIALSTATUS” to know if the first sip peer is down?


You need to use HANGUPCAUSE, and even then some of the causes, if taken literally, could make you dial the phone twice. If you only use SIP, there may be no conflict.

Hi david55,

I was using the following as dialplan, and set a invalid IP for a sip peer.

When I am calling a number using a sip client,
HANGUPCAUSE is always 0,

Can I say, this sip peer is dowm, when HANGUPCAUSE = 0 and DIALSTATUS = CONGESTION

exten => 1000, 1, dial(SIP//)
exten => 1000, n, NoOp(HANGUPCAUSE=${HANGUPCAUSE})
exten => 1000, n, NoOp(DIALSTATUS=${DIALSTATUS})
exten => 1000, n, hangup()


HANGUPCAUSE=0 is a bug and there is a race condition involved which means that you can get one of two results, which have different DIALSTATUS values.

You get a different result again if you use qualify, and that fails.

Hi david55

I tried to use qualify, I got the same result.

Whatever, this bug is reported at April. It is still open, What can I do? I don’t want to wait this bug being fixed.

Best Regards,