Portal Home > Knowledgebase > Articles Database > assign IP to java process
assign IP to java process
Posted by user_204207, 06-14-2009, 05:04 PM |
Hi,
I'm running centOS 5 and I have a java process, it runs from the main IP. The Java process communicates with an external server, this server only allows 2 connections per IP. I have this process running twice on the main IP, therefore using both the single IP connections. My server has multiple IPs and I want to run another copy of this java process from another IP. How would I go about this? Is it possible?
cheers
|
Posted by UNIXy, 06-14-2009, 05:29 PM |
The java program has to have that capability built-in. If you have the source code of the java program, you could build a dynamic list of local IP address then round robin on that list with Socket(). That will effectively tell your program to use such and such IP address as the source address.
See: http://java.sun.com/j2se/1.4.2/docs/...Address,%20int)
Regards
|
Posted by user_204207, 06-14-2009, 08:39 PM |
Not that I'm doubting what you're telling me, just looking for further information: If this is the case, how do things like directadmin work? I create an account, "google.com" and assign it a dedicated IP, whenever you visit the IP you're shown the contents of the folder for that account, that to me says that the folder has been assigned an IP. Maybe I'm understanding it wrong but that's how I see it.
ty
|
Posted by Lightwave, 06-14-2009, 08:58 PM |
Yes, you are (understanding it wrong).
You will need the source for the java app so that you can tell it to specifically bind to a particular ip assuming that capability isn't already built in.
|
Posted by foobic, 06-14-2009, 09:27 PM |
Yep, the only connection between your dedicated IP address and a certain directory is your Apache config, which won't help you here. If using a non-default local ip isn't an option offered by your program and you don't have access to the source then you're stuck.
Unless perhaps some iptables magic could transform this for you... Iptables gurus: Is it possible to connect, say, a certain local port to a specific outbound ip / port?
|
Posted by hhw, 06-15-2009, 02:52 AM |
You would have to do NAT in both directions in order for it to work, and be able to modify the rules without resetting the states of active connections. I'm not sure if that's the default behavior with IPTables or not (it is with pf), but I can't see why it wouldn't be.
So, you would have to do something like:
1. launch app 2x
2. modify iptables rules to change the src ip for any outbound packets going to specified remote ip and port.
3. modify iptables rules to change the dst ip for any inbound packets destined to your specified local ip to your main ip.
4. repeat
You can probably script this process easily enough, but the approach is definitely ugly.
A more elegant solution, if your java app is a proper binary (i.e. compiled into machine code) and can legally be modified, is to use a disassembler. It should be easy enough to find where it makes the "bind" system call, which will probably have the INETADDR_ANY address (expressed as a NULL value).
I imagine you would still be able to do something similar with java bytecode.
You could then make copies of the binary, and hexedit each at the appropriate location with the source IP you want.
|
Posted by Lightwave, 06-15-2009, 03:15 AM |
lol... given his reply to UNIXy... I'm not betting he'll understand anything you said there hhw :p
|
Add to Favourites Print this Article
Also Read