[wildfly-dev] WildFly Server IP Address and Port

Brian Stansberry brian.stansberry at redhat.com
Tue Sep 1 16:31:41 EDT 2015


That JMX operation (or the CLI equivalent[1]) will return 0.0.0.0 which 
really is the bound address but AIUI isn't what's wanted.

If the server is configured to use 0.0.0.0, there is no single 
"WildFly.getHostAddress()". That setting means the relevant sockets will 
be listening on all available interfaces on the machine. Which of those 
is the one that's useful to a particular client depends on the network 
topology.

BTW, if you know the names of the nics in your target environment but 
don't know the addresses, WildFly (and EAP) let you configure the 
interfaces to use a particular nic. If binding to 0.0.0.0 is a 
workaround for not knowing the actual addresses, that may help. For example:

<interface name="public">
    <nic name="eth0"/>
</interface>

The 'name' attribute also allows expressions:

<nic name="${my.public.nic:eth0}"/>

With that kind of config, the JMX query Filippe showed will provide a 
regular address.

[1] The CLI op:

[standalone at localhost:9990 /] 
/socket-binding-group=standard-sockets/socket-binding=http:read-attribute(name=bound-address)
{
     "outcome" => "success",
     "result" => "0.0.0.0"
}

On 9/1/15 12:25 PM, Filippe spolti wrote:
> Hello Arun,
>
> I usethis code w/ Jboss 7 and wildfly 8, i didn't test with wildfly 9/10.
>
>          MBeanServer mBeanServer =
> ManagementFactory.getPlatformMBeanServer();
>          String url = null;
>          try {
>
>              ObjectName http = new
> ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=http");
>              String jbossHttpAddress = (String)
> mBeanServer.getAttribute(http,"boundAddress");
>              int jbossHttpPort = (Integer)
> mBeanServer.getAttribute(http,"boundPort");
>              url = jbossHttpAddress + ":" + jbossHttpPort;
>              log.fine("Url obtained from the system: " + url);
>          } catch (Exception e) {
>              log.severe(e.getStackTrace().toString());
>          }
>          return url;
>
> regards.
>
>
> On 09/01/2015 02:20 PM, Arun Gupta wrote:
>> Assuming WildFly is bound to all available IP addresses using -b
>> 0.0.0.0, is there a WildFly-specific API that can be used to obtain
>> the IP address where the server is running?
>>
>> Ideally, I'd like something like:
>>
>> WildFly.getHostAddress()
>> WildFly.getHostPort()
>>
>> It could be running in a Docker container, in AWS, on my local laptop,
>> in OpenShift, or any where else and would like the IP address to be
>> returned correctly.
>>
>> Suggestions?
>>
>> Arun
>>
>
>
>
> _______________________________________________
> wildfly-dev mailing list
> wildfly-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/wildfly-dev
>


-- 
Brian Stansberry
Senior Principal Software Engineer
JBoss by Red Hat


More information about the wildfly-dev mailing list