Openhab using port 40545 - for what?

After installing openhab2 on a Raspberry Pi, I realise that it opens port 40545. Why? - and what is it used for?

that’s most likely a client connection to/from your system (not necessarily OH2).

lsof -i :40545
netstat -atn |grep 40545

(apt-get install lsof if needed)

Thank you !

The port number varies and it is only open, when openhab2 is started – also no web-clients connected
When openhab2 is closed (systemctl stop openhab2) the port is not open!

I am usng the following bindings:
MQTT
Astro
YahooWeather

Sendt fra Mail til Windows 10

it could be the connection to the broker
check with lsof and you will identify the processes involved in the connection.

example:

root@homer:/var/lib/openhab2# lsof -i :35295
COMMAND     PID      USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
mosquitto 26086 mosquitto    6u  IPv4 10183621      0t0  TCP localhost:1883->localhost:35295 (ESTABLISHED)
java      26395   openhab   46u  IPv6 10182498      0t0  TCP localhost:35295->localhost:1883 (ESTABLISHED)

OH (java process) has initiated (port 35295) a tcp connection to the broker (port 1883)
OH is not listening to this port but it’s using it to establish the connection to the MQTT server

the process is ‘java’

more info:
pi@raspberrypi:~ $ systemctl status openhab2

pi@raspberrypi:~ $ systemctl status openhab2
● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled)
   Active: active (running) since ons 2017-07-26 06:26:54 CEST; 5min ago
     Docs: http://docs.openhab.org
           https://community.openhab.org
  Process: 19375 ExecStop=/usr/share/openhab2/runtime/bin/stop (code=exited, status=0/SUCCESS)
 Main PID: 22055 (karaf)
   CGroup: /system.slice/openhab2.service
           ├─22055 /bin/bash /usr/share/openhab2/runtime/bin/karaf server
           └─22334 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtim...
pi@raspberrypi:~ $ sudo netstat --tcp --listening --programs --numeric
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:2121            0.0.0.0:*               LISTEN      602/owhttpd
tcp        0      0 127.0.0.1:46511         0.0.0.0:*               LISTEN      22334/java
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      22334/java
tcp        0      0 127.0.0.1:4304          0.0.0.0:*               LISTEN      579/owserver
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      791/sshd
tcp        0      0 0.0.0.0:8087            0.0.0.0:*               LISTEN      1005/ow2mqtt-web
tcp        0      0 0.0.0.0:8443            0.0.0.0:*               LISTEN      22334/java
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      436/mosquitto
tcp        0      0 0.0.0.0:1884            0.0.0.0:*               LISTEN      436/mosquitto
tcp        0      0 127.0.0.1:8101          0.0.0.0:*               LISTEN      22334/java
pi@raspberrypi:~ $ sudo systemctl stop openhab2
pi@raspberrypi:~ $ sudo netstat --tcp --listening --programs --numeric
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:2121            0.0.0.0:*               LISTEN      602/owhttpd
tcp        0      0 127.0.0.1:4304          0.0.0.0:*               LISTEN      579/owserver
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      791/sshd
tcp        0      0 0.0.0.0:8087            0.0.0.0:*               LISTEN      1005/ow2mqtt-web
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      436/mosquitto
tcp        0      0 0.0.0.0:1884            0.0.0.0:*               LISTEN      436/mosquitto
pi@raspberrypi:~ $

And lsof:

pi@raspberrypi:~ $ lsof -v :35919
lsof version information:
    revision: 4.86
    latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
    latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
    latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
    constructed: Sat May 5 09:58:04 UTC 2012
    constructed by and on: buildd@build00.raspbian.lan
    compiler: cc
    compiler version: 4.6.3 (Debian 4.6.3-1.1+rpi2)
    compiler flags: -g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -DLINUXV=32012 -DGLIBCV=213 -DHASIPv6 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DHAS_STRFTIME -DLSOF_VSTR="3.2.12" -O
    loader flags: -L./lib -llsof -fPIE -pie -Wl,-z,relro -Wl,-z,now
    system info: Linux build00.raspbian.lan 3.2.12-mx5 #1 PREEMPT Mon Mar 26 15:04:12 PDT 2012 armv7l GNU/Linux
    Anyone can list all files.
    /dev warnings are disabled.
    Kernel ID check is disabled.
pi@raspberrypi:~ $

lsof -i :46511 (or any other port)

got it - see above :slight_smile:

I saw that (strange) 46511 listening port from OH… but you posted the output of the version (-v) of lsof (not the select) (-i)

pi@raspberrypi:~ $ lsof -i :35919
pi@raspberrypi:~ $ lsof -v
lsof version information:
    revision: 4.86
    latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
    latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
    latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
    constructed: Sat May 5 09:58:04 UTC 2012
    constructed by and on: buildd@build00.raspbian.lan
    compiler: cc
    compiler version: 4.6.3 (Debian 4.6.3-1.1+rpi2)
    compiler flags: -g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -DLINUXV=32012 -DGLIBCV=213 -DHASIPv6 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DHAS_STRFTIME -DLSOF_VSTR="3.2.12" -O
    loader flags: -L./lib -llsof -fPIE -pie -Wl,-z,relro -Wl,-z,now
    system info: Linux build00.raspbian.lan 3.2.12-mx5 #1 PREEMPT Mon Mar 26 15:04:12 PDT 2012 armv7l GNU/Linux
    Anyone can list all files.
    /dev warnings are disabled.
    Kernel ID check is disabled.
pi@raspberrypi:~ $

the port has changed then
netstat first to identify it, then lsof to see the processes.
(no need to use -v. this will only post the version)

pi@raspberrypi:~ $ sudo netstat --tcp --listening --programs --numeric
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:2121            0.0.0.0:*               LISTEN      602/owhttpd
tcp        0      0 127.0.0.1:35919         0.0.0.0:*               LISTEN      30301/java
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      30301/java
tcp        0      0 127.0.0.1:4304          0.0.0.0:*               LISTEN      579/owserver
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      791/sshd
tcp        0      0 0.0.0.0:8087            0.0.0.0:*               LISTEN      1005/ow2mqtt-web
tcp        0      0 0.0.0.0:8443            0.0.0.0:*               LISTEN      30301/java
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      436/mosquitto
tcp        0      0 0.0.0.0:1884            0.0.0.0:*               LISTEN      436/mosquitto
tcp        0      0 127.0.0.1:8101          0.0.0.0:*               LISTEN      30301/java
pi@raspberrypi:~ $

ok… this is strange…

netstat -atn |grep 35919

please :slight_smile:

(edit: switch to root first to avoid using sudo everytime)

sudo su

then use lsof (it might be that the user pi doesn’t have the permissions to execute lsof…i don’t remember)

yes :slight_smile: there is also a port 8101???

By the way - I am using Zulu SDK embedded as java

that’s normal. that’s the openHAB console ssh port.

8080 = jetty http
8443 = jetty https
8101 = karaf ssh

additional bindings will open up additional listening ports (e.g. Homekit, etc, etc)

Did a few more tests:

Uninstalled all bindings - ghost still there
Uninstalled Zulu java SDK
Installed Oracle SDK - ghost still there

My conculsion - openhab2 must create the open port.
I just hate having open ports not accounted for!!

I checked trafic with wirshark - no trafic on the ghost port at all

what does netstat -atn |grep <port#> show?

root@raspberrypi:~# netstat -atn |grep 41577
tcp        0      0 127.0.0.1:41577         0.0.0.0:*               LISTEN
root@raspberrypi:~#

ok… i can’t image what this could be…
it seems to be coming from the OH2 java process
but there are no connections to this listening port
it is bound to the localhost only, so no remote connections are allowed
but… something is raising this port and I can’t figure it out.

OH2 & O/S versions?

Ok Thank you for your effort
regards
Erik

------ Original Meddelelse ------