Change a source IP of outgoing traffic

Hello.

It’s a lab.

I have an asterisk on my PC and SIP-phone.

The PC has two IP addresses on a interface (vlan2 etc.) - main and secondary (alias).

When the phone connect to main IP address, not problems. When the phone connect to alias - answer is going from main IP address.
If I put a router with NAT between PC and phone an asterisks answer in not come to the phone (source IP address is different).

I need to change source IP address in outgoing packet to secondary IP address of the interface.

Schema:

request
Phone (192.168.1.5/24) ----> (192.168.1.1/24) router (10.1.1.200/24) —> (to 10.1.1.3) (10.1.1.1, 10.1.1.2, 10.1.1.3) vlan2 asterisk PC eth1 ------>…
Asterisk is binding on 0.0.0.0/0 (all interfaces), The phone connect to 10.1.1.3.

reply
asterisk PC vlan2 (10.1.1.1, 10.1.1.2, 10.1.1.3) (from 10.1.1.1 !!! nor from 10.1.1.3) —> 10.1.1.200

I’ve tryed

iptables -t nat -A POSTROUTING -o vlan2 -s 10.1.1.1 -p udp --sport 5060 -j SNAT --to-source 10.1.1.3

but a port number was changed (It’s a work of SNAT). But I need to keep the source port number (5060).

If I wrote

iptables -t nat -A POSTROUTING -o vlan2 -s 10.1.1.1 -p udp --sport 5060 -j SNAT --to-source 10.1.1.3:5060

the outgoing packets was lost at all. (I think, the linux check a binding of services and find an asterisk on this port)

Who know, how to change source ip address of outgoing traffic and keep a source port number?

The most simple is to configure your application to always use only the address that you need.

I think you need a route on your system to the IP address (or subnet) of the other device. It should not take the default route.

Asterisk can’t do it. :frowning:

Main and secondary IP addresses of the interface are in the one network. It not use default route at all.
Phones network is connected to interface and it has a static route.

Do you mean that the openSUSE systems has both NIC with UIP addresses in the same network and that the phone also has an IP address in the same network?

BTW, why do you not post computer facts. That should show everone here what you have and we then do not depend on vague stories.

ip addr

and

ip route

Do you mean that, you have either Asterix Hardware and/or, an Asterix Software product installed in your PC and/or in your (desk) telephone?

For those mild gentle folks who have never been involved in the not so gentle rough-and-tumble of telephony – data streams always in real-time – electrical effects and phenomena which can only be understood if you’ve studied electrical engineering or physics – logical sequences which can only be understood with the help SDL (System Description Language) – Asterix is this:

Asterisk is a framework for building multi-protocol, real-time communications applications and solutions.

You can use Asterisk to build communications applications, things like business phone systems (also known as IP PBXs), call distributors, VoIP gateways and conference bridges.

[HR][/HR]For those of you who are not so convinced –

  • UNIX® was “invented” in the New York offices of AT&T Bell Labs in 1969 – written in assembler – running on a DEC PDP-7 (14-bit machine).
  • Shortly after, Bell Labs and AT&T began the development of the ESS line of digital telephony switches – in parallel to development of similar systems by Plessey (UK) and Ericsson (Sweden).
  • These systems were needed to more efficiently switch the telephone traffic using Pulse Code Modulation (PCM) – Bernard M. Oliver and Claude Shannon (both Bell Labs) refined the knowledge of PCM in the early 1950s.
  • When the copper wire cables were replaced by fibre optics cables, plesiochronous digital hierarchy (PDH) and later synchronous digital hierarchy (SDH) [also known as synchronous optical networking (SONET)] were introduced to increase the (digital) telephone traffic capacity made possible by the switching capacity of the digital telephony switches.
  • A “day one” feature of the AT&T ESS switches was – “Telephony is only a side issue – we’re switching digital traffic.”
  • Parallel to all this, first the Arpanet and then, the Internet, appeared – carried by the PDH and SDH cables used by the telephony companies.
  • And, of course, the Internet Protocol appeared.

What “HenryPootel” is trying to solve is, a fairly common telecommunications issue which the telecom developers normally solve by writing code …

According to Asterisk 16 PJSIP Multiple IP Addresses . Answer from wrong network interface, similar problem was solved by asteriks configuration.