0
A program on my windows PC makes a TCP connection to a IP address e.g.
122.122.122.122
I have made a TCP server on my local machine and made the following change in my hosts file
192.168.1.123 122.122.122.122
because I want that program to connect to my server instead of 122.122.122.122
the problem that the program is still connecting to 122.122.122.122
instead of my server and ignoring hosts file changes.
6In most OSes, the hosts file is only for name to IP address mappings, not for replacing one IP address with another. So I wouldn't expect this to work. – Spiff – 2018-12-30T18:21:15.543
3Additionally to the comment from Spiff the syntax is wrong: it should be
IP names
and notname IP
, i.e. the IP which should be used for the given name is in the first column. – Steffen Ullrich – 2018-12-30T18:26:12.360Does the program really use a hard coded IP rather than a name? How do you know it makes a connection to that IP? Curious to know how you've determined this. – HelpingHand – 2018-12-30T19:02:03.317
@SteffenUllrich Sorry, I just edited that, it's not like that in my hosts file – Adam – 2018-12-30T19:37:23.883
@HelpingHand I'm using wireshark – Adam – 2018-12-30T19:39:38.067
if you
ping -a 122.122.122.122
changing the IP as needed, what name do you get back? Are you sure you can't use a name? – HelpingHand – 2018-12-30T19:42:56.7371You can't reroute an IP address using the hosts file. If your program binds on all interfaces, you can probably bring up a secondary interface with the IP 122.122.122.122 (netmask 255.255.255.255) – davidgo – 2018-12-30T20:37:51.707
@Spiff Yes you are right, can you suggest an alternative in my case? – Adam – 2018-12-30T22:02:03.807
@HelpingHand I'm getting a hostname but setting this hostname in hosts file with my IP doesn't make any change, because the program is connecting directly to that IP – Adam – 2018-12-30T22:05:24.370
@davidgo can you guide me a little bit how to do so? – Adam – 2018-12-30T22:09:22.453
Sorry, no - I am a Linux person. – davidgo – 2018-12-31T00:04:32.333
@davidgo Great, me too but the app that I'm trying to work on is on windows so maybe I can do something on my Linux machine and connect this Windows to my linux machine through a VPN server, any tools suggested on linux? – Adam – 2018-12-31T00:07:13.200
If you use a VPN like OpenVPN just ensure the server endpoint (if it ends on the Windows box) you want to connect to has an IP of 122.122.122.122 and the client side is in the same subnet. – davidgo – 2018-12-31T00:10:09.193