cannot access host from outside with Private IP and Public IP in java

Discussion in 'Java' started by xeon Mailinglist, Feb 13, 2014.

  1. n a Linux OS, when a program get the IP address with "getHostAddress()". it gets the first IP address available.
    In a host with 2 interfaces, eth0 and eth1, the method will get the eth0 IP address by default.

    I have a host that is behind a NAT, and I cannot change the host IP addresses, or the order of the interfaces.
    In the host, eth0 is a private address, and in eth1 is an address that NAT knows.
    If I want to reach the host from outside, I connect to an IP that NAT will translate into the address of eth1.

    I need to use the private IP address to run a java service (Hadoop MapReduce) correctly, and not the eth1 address.
    I tried to set Hadoop with the eth1 address but the service won't run giving me a not allowed exception.

    1 - Now I want to contact the Hadoop service that is running behind the NAT from the internet, and the service is registered with the private address. Is it possible to reach that node?

    2 - If I could bind eth1 to the java service, I could reach the host from outside?

    3 - If I could update the NAT table with the private address of the host, I could already reach the host from outside?
    xeon Mailinglist, Feb 13, 2014
    #1
    1. Advertising

  2. xeon Mailinglist

    Joerg Meier Guest

    On Thu, 13 Feb 2014 14:35:46 -0800 (PST), xeon Mailinglist wrote:

    > n a Linux OS, when a program get the IP address with "getHostAddress()". it gets the first IP address available.
    > In a host with 2 interfaces, eth0 and eth1, the method will get the eth0 IP address by default.


    While I cannot help you with that at all with practical advice, it occured
    to me that there is really no way that this issue is not already solved for
    producs such as Tomcat or Glassfish, both of which are open source. Maybe
    you can find an answer there.

    Liebe Gruesse,
    Joerg

    --
    Ich lese meine Emails nicht, replies to Email bleiben also leider
    ungelesen.
    Joerg Meier, Feb 13, 2014
    #2
    1. Advertising

  3. xeon Mailinglist

    Arne Vajhøj Guest

    Re: cannot access host from outside with Private IP and Public IPin java

    On 2/13/2014 5:35 PM, xeon Mailinglist wrote:
    > n a Linux OS, when a program get the IP address with "getHostAddress()". it gets the first IP address available.
    > In a host with 2 interfaces, eth0 and eth1, the method will get the eth0 IP address by default.
    >
    > I have a host that is behind a NAT, and I cannot change the host IP addresses, or the order of the interfaces.
    > In the host, eth0 is a private address, and in eth1 is an address that NAT knows.
    > If I want to reach the host from outside, I connect to an IP that NAT will translate into the address of eth1.
    >
    > I need to use the private IP address to run a java service (Hadoop MapReduce) correctly, and not the eth1 address.
    > I tried to set Hadoop with the eth1 address but the service won't run giving me a not allowed exception.
    >
    > 1 - Now I want to contact the Hadoop service that is running behind the NAT from the internet, and the service is registered with the private address. Is it possible to reach that node?
    >
    > 2 - If I could bind eth1 to the java service, I could reach the host from outside?
    >
    > 3 - If I could update the NAT table with the private address of the host, I could already reach the host from outside?


    I think that the right solution is to have the service listen on the
    eth1 IP address.

    So I recommend that you investigate the "but the service won't run
    giving me a not allowed exception".

    Arne
    Arne Vajhøj, Feb 14, 2014
    #3
  4. Re: cannot access host from outside with Private IP and Public IPin java

    Arne Vajhøj <> wrote:
    > On 2/13/2014 5:35 PM, xeon Mailinglist wrote:
    >> n a Linux OS, when a program get the IP address with "getHostAddress()". it gets the first IP address available.
    >> In a host with 2 interfaces, eth0 and eth1, the method will get the eth0 IP address by default.
    >> I have a host that is behind a NAT, and I cannot change the host IP addresses, or the order of the interfaces.
    >> In the host, eth0 is a private address, and in eth1 is an address that NAT knows.
    >> If I want to reach the host from outside, I connect to an IP that NAT will translate into the address of eth1.
    >> I need to use the private IP address to run a java service (Hadoop MapReduce) correctly, and not the eth1 address.
    >> I tried to set Hadoop with the eth1 address but the service won't run giving me a not allowed exception.
    >> 1 - Now I want to contact the Hadoop service that is running behind the NAT from the internet,

    > and the service is registered with the private address. Is it possible to reach that node?
    >> 2 - If I could bind eth1 to the java service, I could reach the host from outside?
    >> 3 - If I could update the NAT table with the private address of the host, I could already reach the host from outside?

    > I think that the right solution is to have the service listen on the
    > eth1 IP address.
    > So I recommend that you investigate the "but the service won't run
    > giving me a not allowed exception".


    I agree with Arne and want to add, that if for some reason your Java app
    needs to know the name by which external clients will be able to connect
    to it, then there is "almost" no way other than have that external name
    configured somewhere in the app.

    "almost"? Well, I don't know exactly about "upnp", but there might be a
    way involving upnp if your NAT'ing router allows it.

    The "not allowed" exception likely results from trying to bind to an
    address that the linux box doesn't itself "know" as its own. You really
    need to to have your application bind to the eth1's address in your scenario.
    Beyond that, either read up on upnp or just allow the external address
    (the one that would be given to clients) to be manually configured.
    Andreas Leitgeb, Feb 14, 2014
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,323
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    530
    SpamProof
    Oct 21, 2003
  3. qazmlp
    Replies:
    19
    Views:
    776
    Daniel T.
    Feb 4, 2004
  4. DaveLessnau
    Replies:
    3
    Views:
    413
    Howard
    May 16, 2005
  5. MRe
    Replies:
    6
    Views:
    628
    Tom Anderson
    Jul 5, 2008
Loading...

Share This Page