0

My question might be a bit weird, but here's some background first:

I've got a client with devices in their own network with different IPs (mostly 192.168.x.x). From the outside, I connect to one of those machines with an SSH tunnel and can forward ports from connections to my IP, but a single tunnel/port only works for a specified IP, and the app I'm developing must accept a list of different IPs to work with, and if they're all 127.0.0.1, that won't work even if the port is different (I could map ports 8000-8005 to 192.168.0.1, 8006-8010 to 192.168.0.2, and so on) as it won't work.

So, I'm wondering if there's any way I can, in my local computer, create a "subnet", say, 10.0.0.x where packets going to 10.0.0.2:80 will go through my SSH tunnel to 127.0.0.1:8000, 10.0.0.3:80 will go to 127.0.0.1:8010, and so on? It's like, mirroring the IPs of my client's network in my own environment through the SSH tunnel... like a VPN of sorts. (a VPN was discussed, but it's complicated on the other end to set up, so I only have the SSH tunnel to work on).

Any ideas are greatly appreciated!

Note: this was already asked on SuperUser, but I did some search here and I think this stack fits better as I've seen people more experienced with networks over here. I'm also looking for something like packet forwarding but with IPs that don't exist in my network but that I can simulate (10.0.0.x), something like:

10.0.0.1:80 --> 127.0.0.1:8000
10.0.0.2:80 --> 127.0.0.1:8001
10.0.0.3:80 --> 127.0.0.1:8010

And so on...

3
  • 1
    If you're developing the app, why can't you connect to a different port? And why aren't you using IPv6, in which this problem just doesn't exist? Aug 3, 2018 at 13:09
  • Because the real app needs to use different IPs. It's like a device scanner, so each IP is treated as a different device (which may contain multiple ports) so I can't use the IP:Port combination to differ between them. IPv6 is out of the question, my client does not have support for it and neither do I, and their devices do not have access from outside other than through a SSH tunnel.
    – DARKGuy
    Aug 3, 2018 at 18:11
  • Hm, well you're in a bit of a mess there. I suppose you could probably pull some iptables trick, but I don't have the exact invocation offhand. Hopefully you and your client will get IPv6 soon. Aug 3, 2018 at 19:09

1 Answer 1

0

Well, after some long hours of research and some pointers by Michael Hampton, I found out my solution using IPTables, I found it through here:

https://www.linuxquestions.org/questions/linux-software-2/route-locally-generated-traffic-to-ip-port-to-localhost-port-300294/

So my command to forward packets from non-existing fake IP to my own computer was:

iptables -t nat -A OUTPUT -m tcp -p tcp -d 10.0.0.1 --dport 80 -j DNAT --to-destination 127.0.0.1:8000

I'm not sure what all of the parameters are and how do they exactly work, but this will redirect 10.0.0.1:80 -> 127.0.0.1:8000.

Thanks!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .