my dog learned polymorphism*
The moose likes General Computing and the fly likes Redirecting request for an IP to another IP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Redirecting request for an IP to another IP" Watch "Redirecting request for an IP to another IP" New topic
Author

Redirecting request for an IP to another IP

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Howdy,

I'm trying to achieve something whereby any requests made from a Windows PC (machine A) to an IP lets say 223.223.223.223 (on a specific port lets say 1888 [Edit:even if it does that on all ports its fine]) should get redirected/rerouted to 192.168.1.1 (port 1888). The 223.223.223.223 is external IP and 192.168.1.1 is the internal IP of the same machine. So if from machine A if I open a browser and hit 223.223.223.223 or from any java code running on machine A if I hit 223.223.223.223 then it should go to 192.168.1.1. I tried changing the host file but that doesn't seem to work as windows is not doing a lookup. I think I can do something like this if I install a firewall on machine A but I'm not sure about that (maybe I need a proxy or something). Does anyone have any clue about how to achieve something like this?

Thanks in advance.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
A hosts file is used for translating domain names to IP addresses; it would work if you wanted to redirect accesess to "www.domain.com" to 192.168.1.1. But it would be used for all ports, not just a specific one.

A proxy would work if the source app can be made to use it - browsers can be set up to use them, but I don't think connections from arbitrary processes can be forced through one if their code isn't written with that in mind.

The built-in router of a firewall would indeed be able to do this via port forwarding, but I'm not sure if the firewall that ships with Windows can be configured that way.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Tim Moores wrote:A hosts file is used for translating domain names to IP addresses; it would work if you wanted to redirect accesess to "www.domain.com" to 192.168.1.1. But it would be used for all ports, not just a specific one.

All ports is fine (I've edited my post to reflect that). But when the request is made for an IP windows doesn't seem to consider the host file.

Tim Moores wrote:The built-in router of a firewall would indeed be able to do this via port forwarding, but I'm not sure if the firewall that ships with Windows can be configured that way.

It would be helpful if you know about any firewall (may not come with windows that's fine) that you know of which can do this?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
But when the request is made for an IP windows doesn't seem to consider the host file.

Correct - it's used only for translating domain names, not IP addresses.

It would be helpful if you know about any firewall (may not come with windows that's fine) that you know of which can do this?

Not sure what one would use on Windows; ipfilter/ipf and iptables are common Unix firewalls/IP routers. The hardware router on your network should have one built in.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Thanks Tim, that was helpful. I'll check with the networks department of our office if they know of any such firewall (or maybe configure a router)...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirecting request for an IP to another IP