Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2008
    Posts
    972

    assign IP to java process

    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

  2. #2
    Join Date
    Feb 2008
    Location
    Houston, Texas, USA
    Posts
    2,955
    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
    UNIXy - Fully Managed Servers and Clusters - Established in 2006
    [ cPanel Varnish Nginx Plugin ] - Enhance LiteSpeed and Apache Performance
    www.unixy.net - Los Angeles | Houston | Atlanta | Rotterdam
    Love to help pro bono (time permitting). joe > unixy.net

  3. #3
    Join Date
    Jul 2008
    Posts
    972
    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

  4. #4
    Join Date
    Apr 2003
    Location
    San Jose, CA.
    Posts
    1,622
    Quote Originally Posted by citricsquid View Post
    Maybe I'm understanding it wrong but that's how I see it.

    ty
    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 certain ip assuming that capability isn't already built in.

  5. #5
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Yep, the only connection between your dedicated IP address and a particular 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 particular local port to a specific outbound ip / port?
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  6. #6
    Join Date
    Oct 2002
    Location
    Vancouver, B.C.
    Posts
    2,656
    Quote Originally Posted by foobic View Post
    Yep, the only connection between your dedicated IP address and a particular 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 particular local port to a specific outbound ip / port?
    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.
    ASTUTE HOSTING: Advanced, customized, and scalable solutions with AS54527 Premium Canadian Optimized Network (Level3, PEER1, Shaw, Tinet)
    MicroServers.io: Enterprise Dedicated Hardware with IPMI at VPS-like Prices using AS63213 Affordable Bandwidth (Cogent, HE, Tinet)
    Dedicated Hosting, Colo, Bandwidth, and Fiber out of Vancouver, Seattle, LA, Toronto, NYC, and Miami

  7. #7
    Join Date
    Apr 2003
    Location
    San Jose, CA.
    Posts
    1,622
    lol... given his reply to UNIXy... I'm not betting he'll understand anything you said there hhw :p

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •