How to change OH2 port numbers on PI

For TWO hours, I’m trying to find a guide on where to change the OH2 port numbers.
Without success. I’m on google search result page 3 and still nothing.
Also nothing in the setup guide I’m following.

:slight_smile: you should search within this community forum.
Examples: [Link 1] [Link 2]

Try the following:

In /etc/default/openab2 (edit the file and add the last 2 lines)



sudo systemctl daemon-reload
sudo systemctl restart openhab2

Verify if OH2 is listening to the new TCP (http) port with:

sudo netstat -atn | grep 8081

Assuming an apt-get installation method of OH2RC1 on Raspbian Jessie (you need to give more info)

Don’t rage… keep it kool :sunglasses:


Great comprehensive answer @Dim

Did you try the official documentation? It’s in there, actually was added just a few days ago :wink:

1 Like

And that is exactly what worries me in the compelete OH story.
I found the file (after an hour more, but:
in the following folder /usr/share/openhab2/runtime
and it was called “setenv”

The file you are referring to does not even exist.
it is an apt-get installation - not sure how to tell the version to download.
Had to do a complete reinstall today (basically every time when I want to change something).
It costs me a day at least every time to get it up and running again.
Currently, OH is not finding the sitemap file anymore. Just copied the conf back from a backup to: etc/openhab2
Most probably the wrong place.

Nope, not wrong place - apparently wrong permissions as copied thru Samba.

1 Like

After the installation, you will receive the following instructions in the linux shell:

### NOT starting on installation, please execute the following statements to configure openHAB to start automatically using systemd
 sudo /bin/systemctl daemon-reload
 sudo /bin/systemctl enable openhab2.service
### You can start openhab2 by executing
 sudo /bin/systemctl start openhab2.service

If you run systemctl enable openhab2.service it should create the /etc/default/openhab2 file (if I am not wrong)

You could also use the /usr/share/openhab2/runtime/bin/setenv file to modify the ports but this is not recommended since this file may be replaced during the next upgrade.

That has been all done.
except that I did not start openhab2.
I just rebooted the pi.

and there is no /etc/default/openhab2 file created? strange

what is the output of the following command:

apt-cache policy openhab2

If this doesn’t work, try:

apt-cache policy openhab2-online (or offline, depending on the package that you used)


i´ve changed the ports in the /etc/default/openhab2 to:


When i restart openhab2 i see may “Permission denied” in the log. Seems the ports cannot be bound to 80 and 443.
I using openhabian.

@ThomDietrich maybe it is possible to change the openhab doc there is a wrong path - there stand the path is /etc/defaults/openhab2 (defaultS - with a S at the end) thats the point I stumbled.

The default ports 8080 and 8443 can be changed by setting the environment variables OPENHAB_HTTP_PORT resp. OPENHAB_HTTPS_PORT. In an apt installation, you would best do this in the file /etc/defaults/openhab2.

Just for others who maybe reading this thread: The OH2 process runs under the regular Linux user openhab
This user does NOT have access to privileged ports (TCP/IP port numbers below 1024) by default.
There are workarounds to this but it is better to use Running openHAB Behind a Reverse Proxy if you want to use TCP 80/443