4

I have a local (HTTP) server running on my (Linux) machine (listening on 127.0.0.1:port) and a local application that connects to it as a client. Both the server and client applications are proprietary and I can only change some basic config for both. I have had this set up working fine until recently when the client application was updated. The client application now seems to require that the server it connects to must be "on the internet" so it is disallowing connections to 127.0.0.1 and other "local-like" addresses such as 10.0.*.* and 192.168.*.*.

As a workaround, I am now using ngrok to get a remote address for my local server and the client application happily works with that. However, that is a manual/slow process to run ngrok and update the client application's config and it requires an internet connection and going through ngrok's servers.

I am wondering if there is a way to "fake" an "internet-like" IP address to resolve directly to my local machine.

I have looked into "dynamic DNS" solutions but they require changes to router config that I often don't have control over.

What I am thinking is along the lines of setting some porn site's "internet-like" IP to "resolve" to my local machine on my local machine using some kind of "virtual network adapter" BUT I don't want to spend a lot of time building such a set up. Hence, the question, is there an EASY way to do this?

7
  • 4
    Is there a reason why you don't want to add a non-local-sounding IP address to one of your interfaces? Commented Feb 11, 2018 at 5:40
  • @IgnacioVazquez-Abrams No, I am open to it. I just don't know an easy/quick way of doing it.
    – SBhojani
    Commented Feb 11, 2018 at 6:04
  • @IgnacioVazquez-Abrams Is garron.me/en/linux/add-secondary-ip-linux.html the kind of thing you are suggesting?
    – SBhojani
    Commented Feb 11, 2018 at 6:11
  • @IgnacioVazquez-Abrams I just tried ip address add 31.192.120.36/31 dev lo and the client application doesn't like the that either. Could it be checking the local ip config?
    – SBhojani
    Commented Feb 11, 2018 at 6:39
  • 2
    @SBhojani don't add it to dev lo, add it to eth0. If you've been adding the local network addresses like 192.168.*.* to dev lo, try those on the eth0 adapter instead of lo and they might work there. Commented Feb 13, 2018 at 10:54

5 Answers 5

1
+50

use iptables?

iptables -t nat  -I OUTPUT --src 0/0 --dst dest_ip -p tcp --dport 80 -j REDIRECT --to-ports 80

(not sure about the chain though) This should in effect redirects --transparently-- any traffic going to dest_ip:80 to localhost:80.

the des_ip is any ip that makes the application happy.

5
  • That seems to be working. Any way to make that permanent?
    – SBhojani
    Commented Feb 16, 2018 at 13:43
  • iptable-save/restore (some distribution have an init script for that), or any suitable firewall management thingy (my preferred would be shorewall) Commented Feb 16, 2018 at 15:36
  • For my own record and for anyone else that it might help, iptables-save didn't work for me as I was using FirewallD. I had to create a direct configuration rule with the table nat, the chain output and the args --src 0/0 --dst dest_ip -p tcp --dport 80 -j REDIRECT --to-ports 80.
    – SBhojani
    Commented Feb 20, 2018 at 12:00
  • yeah, if using something like shorewall/ufw/firewalld better not touch iptables directly and use whatever meas that has to add rules. Commented Feb 20, 2018 at 18:25
  • For my own record and for anyone else that it might help, iptables -t nat -I OUTPUT --dst dest_ip -j REDIRECT is enough to redirect ALL ports on dest_ip to "localhost".
    – SBhojani
    Commented Apr 8, 2018 at 2:04
1

You can add as an alias a "real" IP on the server, i.e. 1.2.3.4/32 and try connecting to this address form the client application, if it's on the same computer. If your client application in on a different computer, use something like 1.2.3.4/24 for the server and 1.2.3.5/24 for the client, provided they're both in the same LAN. This type of addresses is not assigned in the internet, so you won't face any connectivity problems.

2
  • I am not sure how to do this. I can only configure the IP and the port for both the server and the client.
    – SBhojani
    Commented Feb 16, 2018 at 13:26
  • Depending on your distribution, there will be a standard way of doing this. Google should be of help here, for example a query of "how to add an alias ip address on debian/ubuntu/centos/mint...", should guide you to a simple way of adding an alias ip address to your ethernet adapter.
    – gmelis
    Commented Feb 16, 2018 at 14:30
0

You could try an ip address in one of the less well-known reserved, or not routable, ranges, betting on a poor implementation in your client-server application.

Refer to https://en.m.wikipedia.org/wiki/Reserved_IP_addresses

2
  • Not sure how to do that. For example, how would I make a server listen on 0.255.0.0 and how do I make a client connect to 0.255.0.0 "locally".
    – SBhojani
    Commented Feb 16, 2018 at 13:22
  • Try 1.1.1.1 and 1.1.1.2 netmask 255.255.255.0 Commented Feb 16, 2018 at 17:57
0

I would use virtualization. You can make a fake little world for your software to live in. This can be as elaborate or as simple as you want. The benefit here is that you can use public IP addresses without messing up networking for the entire LAN you are attached to. Just make sure that the virtual interfaces are set to "host only" or "virtual network only".

You could even make two machines. One client and one server both in the public subnet, so they can talk to each other without routing. This could exist completely in the virtual network and not even be visible to the host, if you desired.

0

Maybe you can use an Internet simulator like INetSim. It simulates (provides fake) common internet services, so the program thinks it's on the Internet. It is e.g. used for analyzing the network behaviour of malware in a closed and safe environment, and this program is then used to trick it to believe it is the Internet, while it's actually not.

It seems like the same scenario as your, so take a look at it and see if you can use it!

You must log in to answer this question.

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