Binding OpenHAB to a specific IP address (as well as localhost)

I just installed OpenHAB with a SMLight SLZB-06P10U using zigbee2mqtt as the coordinator and set up an automation to control a couple of ThirdReality smart plugs based on whether my security system is armed or disarmed. It’s working perfectly and I intend to expand the devices to replace my aging Insteon devices. I installed the 5.2.0 zip with openjdk 21.0.11_p10 and I’m running it on a general purpose Gentoo Linux server with an AMD Epyc 4464P processor and multiple VIPs.

I decided to bind OpenHAB to a specific IP address and did so by editing the these two files:

/mounts/zigbee/openhab/userdata/etc/org.ops4j.pax.web.cfg:

org.ops4j.pax.web.listening.addresses = 192.168.77.2

/mounts/zigbee/openhab/runtime/bin/setenv:

#
# set listen address for HTTP(S) server
#
if [ ! -z ${OPENHAB_HTTP_ADDRESS} ]; then
HTTP_ADDRESS=${OPENHAB_HTTP_ADDRESS}
else
HTTP_ADDRESS=192.168.77.2
fi

That worked but then OpenHAB was no longer listening on localhost so I tried “127.0.0.1,192.168.77.2” but OpenHAB ignored 127.0.0.1 and was still just listening on 192.168.77.2.

I next tired adding this to my openrc startup script:

export OPENHAB_HTTP_ADDRESS=“127.0.0.1,192.168.77.2”

That appeared to work at first glance, ss was showing OpenHAB listening on both IPs but OpenHAB cloud wouldn’t work, I was getting a 404 error when it tried to connect to my local instance. I changed everything back to “0.0.0.0” and now everything works fine but OpenHAB is listening on all IPs. No big deal but my preference is still to bind it to a specific IP plus localhost. Is there a way to do this or should I just leave well enough alone?

Hi,
First welcome to the community!
you might want to have a look in the settings/network settings and click the advanced check box within the OpenHab GUI you may find you can set up your preferred configuration there

Hi @jah3947

i have setup openhabian a few times with a static address for openHAB and while i seem to have some success i often find something bizarre will catch me so have standarized on a fixed DHCP lease because if ever i need to change its very easy just edit the DHCP leases. Additionally, having the managed devices on fix addresses is critical to sure system stability and so I always opt for static DHCP leases with no expiration.

Can zigbee2mqtt is be installed as an additional component of Openhabian?
I thought it was entirely separate application.

No, you’re right it is a separate application.

Thank you! And thanks for the suggestion, I had not noticed that setting. Oddly, it lists all my VIPs and the primary IP that I want to bind it to is actually selected, however it is listening on all IPs.

I use dhcp reserved addresses for some of my devices but for this server it needs to be a static IP configured on the server. But I sometimes do both for some devices just in case.

zigbee2mqtt can be installed with openhabian. That’s one purpose of openhabian: Install services that are often used together with openhab.
It’s under “optional components”.

I don’t know the answer to your specific question. You might find the answer on the Karaf repo/forum/docs as all the networking stuff is really handled by Karaf.

In the meantime, you can achieve what you want with the firewall. Let OH listen on all but the host based firewall only allows connections from localhost and the one IP address.

Alternatively you can configure OH to only accept connections from localhost and set up a reverse proxy to expand that to the IP address.

I’m certain Karaf supports what you are after out of the box though so look into that first.

Thanks, good suggestion. I’ll look at Karaf directly to see if I can find an answer.