Search code examples
network-programmingtcpportforwardingports

How to make multiple requests from the same IP but different ports (each from different location)


I have this scenario: an IP (eg. 192.168.0.109). It's possible to make some requests from the same IP but thru different ports ? More, each port to be from a different zone. Something like a proxy, but for ports.

So, I would like to achieve something like this:

192.168.0.109:20000 -> Paris
192.168.0.109:20457 -> Lyon
192.168.0.109:21341 -> Sydney

I read something about TCP Proxy but I am not sure if this is exactly what I am looking for.

Can anyone explain me if this is achievable and if so, describe me the entire process and what would the steps be in order to have something like this running ?


Solution

  • Each new TCP connection will automatically be assigned a local IP and random port number from the kernel's ephemeral ports pool by default. You can optionally bind(2) the socket to the desired local IP and/or port before connect-ing to the server. You can bind() to a desired IP and let the kernel choose the port for you.