I got an application (no source code) calling a server (hard coded IP) and expecting an answer before starting (a kind of login).
Cause the server is down half of the time, I want to create a dummy server which will emulate the behavior of the official server.
My problem:
How can I redirect the traffic to my local machine?
I want all the request send to IP w.x.y.z to be re-routed to localhost (where my dummy server is running)
More info:
- my dummy server is an apache/php solution.
- I tried to edit the hard coded IP in the application with an hex editor, but some checksum fail when I start the application.
- cause the IP is hard coded in the application, I cannot use the hosts file.
- I'm running win xp.
-
Well, you could try the following:
Set up a specific route for that IP address, which will use the dummy server as gateway, like this:
route add -host w.x.y.z/32 gw dummy-server-ip
For this you will need either access to the main router for your network, or you have to do it on the machine that is sending the requests. This effectively sends the TCP packets with the w.x.y.z IP address to the MAC address of the dummy-server. So now you need to make sure the dummy server knows what to do with them.
Then add the w.x.y.z IP address as a secondary address to the dummy server.
Finally update the apache config on the dummy server to ensure it also listens on the w.x.y.z address, and make sure that the vhost on the dummy server accepts incoming requests for both the IP address and the domain name.Please note that this will only work if there are no other routers between the requesting machine and the dummy-server. And if there are any firewalls involved, they also need updating.
Loda : Thanks for the answer it's look exactly like what I want to do. but, I got problem implementing it. I will prefer to not touch the router, also because, the solution should be exclusive for my machine. The command you put me as an example does not work on my win xp. I also tried "route add w.x.y.z 127.0.0.1" without success. I do not have firewall/router between the application and the dummy server. they both run on the same machine. (But, I do have a software firewall:kaspersky) I will really appreciate some help about how to set this route.wolfgangsz : There is a route command available for Windows: route ADD w.x.y.z MASK 255.255.255.255 127.0.0.1 This will point the route back onto your own machine. You might have to open the firewall for incoming requests on the w.x.y.z address.Loda : I did try to add a route using this command with no success. don't know why.Loda : "route add 62.1.1.10 mask 255.255.255.255 127.0.0.1" The error message say : "error adding the route: incorrect parameter" (translated from ES)wolfgangsz : Hmm, maybe you need to replace 127.0.0.1 with the actual LAN IP address of that interface. I have never tried anything like this before, so there is a little guesswork involved.Loda : I could add the route ! (I will have sweared I did try with the local IP without succes. Weird.). Thanks a lot for the guidance. Anyway, even with the route, I cannot open my web server from the local browser using the external IP.From wolfgangsz -
You could probably bang something together with iptables. Here's something I once used but am no longer doing to give you a toehold:
*nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A PREROUTING -d 172.16.25.202 -i eth0 -p tcp -m tcp --dport 25 -j DNAT --to 172.16.27.59:8025 -A POSTROUTING -o eth0 -j MASQUERADE COMMITNB: I did this a long time ago, there may be mistakes in there
The only thing I see that might be an issue is that it's specific to the interface. I think that the eth0 is only for the inbound part, so using an ip on the lo interface (127.0.0.1) as the target might still work...
Jason Berg : That'd be a great answer...but he's running Windows XP.jj33 : Doh! I think I saw "apache/php" and stopped reading. Even after you pointed it out I scanned three times before I saw it. Oh well, I'll leave it, maybe it'll help someone somewhere somewhen.From jj33 -
This would be a total hack, but you could try assigning the IP of the server in question as an additional IP on you local interface, instructions here
Loda : This looks great !. but I cannot try it now, (my internet is down, I'm tethering on 3G..). I give you some feedback at the end of next week.Loda : This really rocks ! working great, very easy solution. thanks !Swish : Sweet, glad to hear it :)Loda : Precision: Adding a 2sd IP to my NIC got a side effect; all IP in the same external subred are redirected to my NIC. ie: when adding IP 50.51.51.51, IP 50.51.51.52 is not reachable anymore. This is caused by the route 50.51.51.0 and the route 50.255.255.255. Workaround: add route 50.51.51.52 -> normal gateway.From Swish
0 comments:
Post a Comment