Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

related: http://serverfault.com/questions/66254/how-to-redirect-traffic-to-one-ip-to-a-different-ip-on-windows-server-2008

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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

share|improve this answer
    
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 Aug 20 '10 at 8:41
    
This really rocks ! working great, very easy solution. thanks ! –  Loda Aug 20 '10 at 14:23
    
Sweet, glad to hear it :) –  Swish Aug 20 '10 at 16:40
    
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. –  Loda Aug 23 '10 at 10:02

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.

share|improve this answer
    
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. –  Loda Aug 19 '10 at 9:08
    
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. –  wolfgangsz Aug 19 '10 at 14:53
    
I did try to add a route using this command with no success. don't know why. –  Loda Aug 20 '10 at 14:22
    
"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) –  Loda Aug 20 '10 at 14:26
    
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. –  wolfgangsz Aug 20 '10 at 17:16

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 
COMMIT

NB: 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...

share|improve this answer
    
That'd be a great answer...but he's running Windows XP. –  Jason Berg Aug 18 '10 at 14:57
    
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. –  jj33 Aug 18 '10 at 15:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.