# Asterisk and multiple address

**URL:** <https://community.asterisk.org/t/asterisk-and-multiple-address/39284>\
**Category:** Asterisk Support\
**Created:** [May 22, 2012, 7:18am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284 "2012-05-22T07:18:54Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 22, 2012, 7:18am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/1 "2012-05-22T07:18:54Z")

</div>

I have a asterisk with two real ip-address from two different ISPs.

For example :  
eth0 192.168.0.1  
eth1 172.168.0.1

ip routing :  
default via 192.168.0.1 dev eth0

In sip.sonf :  
udpbindaddr=0.0.0.0

When the incoming packet going to 172.168.0.1 then ougoing packet has source address is 192.168.0.1 , and this rightly and this is rightly according the OS settings, but is more correct send a packet with source address is 172.168.0.1 .

How to do it with a asterisk?

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [May 22, 2012, 7:52am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/2 "2012-05-22T07:52:00Z")

</div>

192.168.0.1 is not a real IP address. I’m not sure whether the 172 one is also in the same class.

If you are dual homed, you should really have an autonomous system number and be routed as dual homed. I don’t think Asterisk has support for broken dual homed systems, although there may be tactics, using multiple instances, one for each external address.

---

<div class="post-metadata">

**Author:** ![leemason](https://avatars.discourse-cdn.com/v4/letter/l/57b2e6/32.png) [@leemason](https://community.asterisk.org/u/leemason)\
**Post date:** [May 22, 2012, 7:58am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/3 "2012-05-22T07:58:54Z")

</div>

These are obviously internal addresses. I assume they go out via a router to the ISP?

If you are routing packets to an external address they will use the default gateway so go out via 192.168.0.1.

If you want routed packets to go out via 172.168.0.1 then you will probably need to hand craft some routes to the specific IP addresses that you want to packets to go to so if you want packets to go to 79.99.99.99 via eth1 then you need a route pointing out through eth1 for that address.

Basically you have to have a default gateway going out via one ethernet adapter and if you want to send routed packets out through the other you need to tell the system about them.

---

<div class="post-metadata">

**Author:** ![dejanst](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dejanst](https://community.asterisk.org/u/dejanst)\
**Post date:** [May 22, 2012, 8:01am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/4 "2012-05-22T08:01:02Z")

</div>

You should add an IP route for the second SIP provider:

```auto
route provider_softswitch_ip 255.255.255.255 dev eth1
```

I have a similar setup on multiple sites and it is working flawlesly. I just needed to configure the IP routing part on Linux box, Asterisk communication just followed.

---

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 22, 2012, 10:38am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/5 "2012-05-22T10:38:26Z")

</div>

> [@david55](#):
>
> 192.168.0.1 is not a real IP address. I’m not sure whether the 172 one is also in the same class.

> [@leemason](#):
>
> These are obviously internal addresses. I assume they go out via a router to the ISP?

I said “for example”.

---

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 22, 2012, 11:53am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/6 "2012-05-22T11:53:51Z")

</div>

[quote=“dejanst”]You should add an IP route for the second SIP provider:[/quote]This does not solve my problem

---

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 22, 2012, 12:11pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/7 "2012-05-22T12:11:15Z")

</div>

In the SIP package uses the address of 172.168.0.1 and this is the expected, but tcpdump show

`15:54:16.218836 IP 192.168.10.14:5061 > 172.168.0.1.5060: SIP, length: 667
15:54:16.219817 IP 192.168.0.1.5060 > 192.168.10.14.5061: SIP, length: 585`

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [May 22, 2012, 12:38pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/8 "2012-05-22T12:38:13Z")

</div>

Please clarify which non-routeable addresses are actually being used, and which are being used to avoid quoting routeable ones.

What are your settings for externip, externhost, stunaddr and localnet?

What is the topology of your network from the Asterisk box to either a routeable internet interface, or ISP’s SIP box, whichever is nearer?

---

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 22, 2012, 3:43pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/9 "2012-05-22T15:43:45Z")

</div>

[quote=“david55”]What are your settings for externip, externhost, stunaddr and localnet?[/quote]this parameters not used

I show output the tcpdump. Why asterisk answer from 192.168.0.1 if packet going to the 172.168.0.1 ?

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [May 22, 2012, 3:58pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/10 "2012-05-22T15:58:25Z")

</div>

dejanst appears to claim that it works otherwise, but I have always assumed that Asterisk determines up to two addresses for itself when it starts. One its actual address and a second, only if the options I quoted are correctly used, which is the routeable address on the outside of the NAT environment. These being the addresses used in the application layer protocol.

This should not be a problem with a properly dual homed system, with routeable addresses, and its own autonomous system number, although it may be difficult to get ASNs if you don’t have a large range of addresses.

At the IP level, the OS may substitute an address based on the actual interface used, although it is possible that this gets bound at an earlier stage.

Your use of non-routeable addresses in your examples is still causing me a lot of confusion as to whether you are in a NAT environment, or even a completely closed environment.

---

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 23, 2012, 5:35pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/11 "2012-05-23T17:35:46Z")

</div>

Okey… , for example addresses such

eth0 212.212.212.6  
eth1 198.198.198.10

ip routing :  
default via 212.212.212.5 dev eth0

In sip.sonf :  
udpbindaddr=0.0.0.0

tcpdump show this

`15:54:16.218836 IP 93.93.93.14:5061 > 198.198.198.10.5060: SIP, length: 667
15:54:16.219817 IP 212.212.212.6.5060 > 93.93.93.14.5061: SIP, length: 585`

No NAT, everywhere use the real IP address.

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [May 23, 2012, 5:54pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/12 "2012-05-23T17:54:04Z")

</div>

That’s because that is the interface with the default route. I believe you will find that a single socket is used for all SIP traffic.

If they are real internet addresses, it won’t matter, as they will get to the destination either way. The contact address should be what is used for subsequent traffic and the initiator should not be using IP level information to match up sessions. If you had proper multi-homing, either interface could be used for incoming traffic to either address.

If this is some sort of authentication issue, because the ITSP and ISP are the same, you presumably know their IP address range, and you should have explicit routes, down the interface to them, for those address ranges. Actually, if you are seriously muli-homed, you should be running proper routing software (probably gated), to ensure that traffic goes out through the best interface for the destination.

---

<div class="post-metadata">

**Author:** ![dejanst](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dejanst](https://community.asterisk.org/u/dejanst)\
**Post date:** [May 23, 2012, 8:13pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/13 "2012-05-23T20:13:53Z")

</div>

> [@dejanst](#):
>
> ```auto
> route provider_softswitch_ip 255.255.255.255 via eth1_gateway_IP dev eth1
> default via 212.212.212.5 dev eth0
> ```

I still think this should solve your problem.

---

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 24, 2012, 3:33am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/14 "2012-05-24T03:33:49Z")

</div>

I’m not connected to any server. I have a server, and at my addresses are going SIP registration. So I can not make a strict route.  
Asterisk must make the right choice interface, ie what would reply back to where the request came

---

<div class="post-metadata">

**Author:** ![dejanst](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dejanst](https://community.asterisk.org/u/dejanst)\
**Post date:** [May 24, 2012, 6:50am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/15 "2012-05-24T06:50:41Z")

</div>

If the provider SIP server IP is static, you definitly CAN make a static route for that IP address.

Asterisk will not make any choices as from which ETH interface it will send it’s SIP signalling. This decision is made on the basis of the ROUTING TABLE that is configured on the server.

---

<div class="post-metadata">

**Author:** ![axonaro](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@axonaro](https://community.asterisk.org/u/axonaro)\
**Post date:** [May 28, 2012, 8:57am UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/16 "2012-05-28T08:57:28Z")

</div>

[quote=“dejanst”]If the provider SIP server IP is static, you definitly CAN make a static route for that IP address.[/quote] How, I don’t know the addresses of users and/or this addresses may be dynamic ?

---

<div class="post-metadata">

**Author:** ![dejanst](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dejanst](https://community.asterisk.org/u/dejanst)\
**Post date:** [May 28, 2012, 12:35pm UTC](https://community.asterisk.org/t/asterisk-and-multiple-address/39284/17 "2012-05-28T12:35:57Z")

</div>

Oh, I thought that you are having users on LAN (behind some sort of NAT) and connecting to the internet only because of connection to the VoIP service provider. But I see you have extensions logging in from the internet.

The answer to the question:

Can I use Asterisk to distribute services to extensions via internet (the IP addresses of the IP phones are not known before the SIP Registration) on 2 separate NIC-es that have 2 different public IP’s (IP phones connect to either one)?

Is: NO.

If you would know the IP addresses of the IP phones that are connecting to Asterisk, you could set up the Linux routing tables accordingly. But if everything is random, you can not do it in a eazy way.

If you ask me - use one NIC to accept SIP extensions and use the second NIC only for connecting to the SIP provider (which has servers on static public IP’s, so you can configure a static route for NIC1 on your Asterisk server).
