I have asterisk listening on an interface which has a secondary ip
eth0 192.168.1.1/24
eth0:1 1.1.1.1/24
Sometimes when an external sip device tries to register, asterisk would respond as 192.168.1.1 and in other cases as 1.1.1.1. Is there any way to control this behavior? I mean, can I specify what IP address asterisk has to use responding?
That is strange. In my experience, if the default route it set to eth0:1 (with public IP address), Asterisk always uses the public IP address (eth0:1) for communicating with the clients that are communicating with it via the internet/eth0:1 connection.
What version of Asterisk are you using?
Can you do a “sip set debug on” when the problem happens and copy/paste the output here?
Majority of Asterisk servers that I manage have 2 NIC. The reason for that is that almost very TSP in Slovenia is not offering SIP Trunking via Internet, but instead they offer their services via a private VoIP network to which Asterisk needs to be connected directly. So this is an example of my Asterisk server NIC setup:
ETH0 - 192.168.5.45 (private LAN 192.168.5.0/24 where all the local SIP phones are connected to)
ETH1 - 10.10.15.20 (private VoIP network from the TSP 10.10.15.0/22, SIP Trunk is accessible only via this network)
The only thing I need to set is Linux routing table and the NIC configuration files. For communication with local SIP phones Asterisk uses it’s ETH0 IP address, for communication with TSP Asterisk uses it’s ETH1 IP address. How it does that I do not know. I just know it does