Asterisk and multiple address

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

For example :

ip routing :
default via dev eth0

In sip.sonf :

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

How to do it with a asterisk? 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.

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

If you want routed packets to go out via 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 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.

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

route provider_softswitch_ip 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.

I said “for example”.

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

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

15:54:16.218836 IP > SIP, length: 667 15:54:16.219817 IP > SIP, length: 585

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?

[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 if packet going to the ?

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.

Okey… , for example addresses such


ip routing :
default via dev eth0

In sip.sonf :

tcpdump show this

15:54:16.218836 IP > SIP, length: 667 15:54:16.219817 IP > SIP, length: 585

No NAT, everywhere use the real IP address.

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.

I still think this should solve your problem.

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

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.

[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 ?

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).