Network binding DHCP problem

I can’t get dhcplisten to work and I was just hoping that there is a Linux wiz out there that can help me.
I followed the instructions on http://docs.openhab.org/addons/bindings/network/readme.html#permissions

I’m running Ubunto 16.04 minimal image on an Ubuntu C1+.

Tried

$ sudo setcap cap_net_bind_service=+ep `realpath /usr/bin/java`

which didn’t work but since

$ ls -l /usr/bin/java
  lrwxrwxrwx 1 root root 22 Dec 18 16:27 /usr/bin/java -> /etc/alternatives/java
$ ls -l /etc/alternatives/java
  lrwxrwxrwx 1 root root 39 Dec 18 16:27 java -> /usr/lib/jvm/java-8-oracle/jre/bin/java

I ran this instead

$ sudo setcap cap_net_bind_service=+ep /usr/lib/jvm/java-8-oracle/bin/java

and then checked

$ sudo getcap /usr/lib/jvm/java-8-oracle/bin/java
  /usr/lib/jvm/java-8-oracle/bin/java = cap_net_bind_service+ep

But I get an error in the openhab.log

2016-12-21 15:41:09.374 [ERROR] [nding.network.service.NetworkService] - Cannot use DHCP listen: Permission denied (Bind failed)

*.things

network:device:1 [ hostname="192.168.1.113", port="0", retry="1", timeout="5000", refresh_interval="60000", use_system_ping="true", dhcplisten="true" ]

*.items

Switch    Device_1_stat           "Device_1 - Status"                                                                   { channel="network:device:1:online" }
Number    Device_1_time           "Device_1 - Response Time"                                                            { channel="network:device:1:time" }

*.sitemap

Frame label="devices"
{
  Switch item=Device_1_stat
  Number item=Device_1_time
}

Any suggestions??

Besides the different path (mine is /usr/lib/jvm/java-8-oracle/jre/bin/java) everything looks good. Why did realpath /usr/bin/java not work for you??

Did you restart openhab?

Just a hunch: Please name your thing something other than “1”. The rest of your config looks fine.

No idea why it doesn’t work.

$ sudo setcap cap_net_bind_service=+ep 'realpath /usr/bin/java'
  Failed to set capabilities on file `realpath /usr/bin/java' (Invalid argument) The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file

Don’t think the thing name is a problem (but I’ll change it anyway). The ping functionality works perfectly. It’s just DHCP that doesn’t work

Your command is wrong. You need to use ``` `` instead of '. Yes that’s a difference :smiley:

Assuming you are using bash, you can also write…

sudo setcap cap_net_bind_service=+ep $(realpath /usr/bin/java)

I find that’s syntax is more clear for my old eyes. :wink:

Good point. Maybe I should change that in docs.

Using ` instead of ’ works…
DHCP listen works now.

My problem was that I elevated privileges for the wrong java file…

$ sudo setcap cap_net_bind_service=+ep /usr/lib/jvm/java-8-oracle/bin/java

when I should have written

$ sudo setcap cap_net_bind_service=+ep /usr/lib/jvm/java-8-oracle/jre/bin/java

Thx for the help guys!

Hi.
Jumping in here since I have a similar problem. Thing is though that even when I use the “real” file it doesn’t work:

root@cube:~# setcap cap_net_bind_service=+ep /usr/lib/jvm/java-8-oracle/jre/bin/java
Failed to set capabilities on file `/usr/lib/jvm/java-8-oracle/jre/bin/java’ (Invalid argument)
The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file

After some Googling I suspect maybe this is something that is missing in my kernel, but I don’t know how to verify that hypothesis. Also I don’t think I can change kernel (got a somewhat complicated uboot setup), is there any way of going around this?

Could you please post an ls -la of that file?

root@cube:/var/lib/openhab2# ls -al /usr/lib/jvm/java-8-oracle/jre/bin/java
-rwxr-xr-x 1 root root 5916 jan 20 07:59 /usr/lib/jvm/java-8-oracle/jre/bin/java

Seems legit. Too bad. I’m afraid I can’t help here. Is this OS you are running on “Cube” something special? Which java version did you install from where? I’ve seen the exact same error message, but was indeed trying to work with a not exisiting or symlink file…

It’s a CuBox server (from an Israeli company named Solidrun, very nice little computer), hence the name cube. It’s running a normal Debian 8.7, just with a not really standard kernel. The Java is Oracles official one, but I don’t think this error is really Java related. Guess I’ll have to read up on that setcap stuff…

Hi @DanielMalmgren have you find a solution ? I have the same error message (Failed to set capabilities on file…)

Unfortunately not. I still think it’s kernel related but I haven’t succeeded in upgrading my kernel (spent an entire day giving u-boot a hard time but it simply refused). Do you have some special kernel as well?

I run the OH2 official Docker image on my Synology DS415+.
From this Docker issue #5650, the Capabilities functions are not supported by AUFS.
My storage backend is well AUFS:

sudo docker info | grep Driver
Storage Driver: aufs

:frowning:

Doh. One shouldn’t think that listening for dhcp requests depends on which file system you use. The wonderful world of Linux :yum:

Hi, I am just starting to configure OH2 on a Beaglebone Black running Debian.
I cannot get DHCP listen to work, hope it’s appropriate to post in this thread.

I have set the cap_net_bind_service+ep capability for java, but instead of the “Permission denied” error, I now get:

[ERROR] [nding.network.service.NetworkService] - Cannot use DHCP listen: Address already in use (Bind failed)

*.things

Thing network:device:SP3 "Surface Pro 3" [ hostname="192.168.1.20", port="0", retry="1", timeout="5000", refresh_interval="60000", use_system_ping="true", dhcplisten="true" ]

Any idea about what I’m doing wrong?

Answering my question above:
Port 67 was taken by dnsmasq, I removed the package, and it works!

1 Like

I can’t get the DHCP to work either:

23:32:45.590 [INFO ] [smarthome.event.ThingUpdatedEvent   ] - Thing 'network:device:192_168_3_146' has been updated.
23:32:45.641 [ERROR] [nding.network.service.NetworkService] - Cannot use DHCP listen: Address already in use (Bind failed)

Yet, getcap returns::

getcap `realpath /usr/bin/java`
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre/bin/java = cap_net_admin,cap_net_raw+eip cap_net_bind_service+ep

Which shoud not even be needed as java is running as root:
root 4893 4732 1 May23 ? 02:30:10 /usr/bin/java -Dopenhab.home=/opt/openhab -Dopenhab.conf=/opt/openhab/conf -Dopenhab.runtime=/opt/openhab/runtime -Dopenhab.userdata=/opt/openhab/userdata -Dopenhab.logdir=/opt/openhab/userdata/logs -Dfelix.cm.dir=/opt/openhab/userdata/config -Dorg.osgi.service.http.port=8080 -Dorg.osgi.service.http.port.secure=8443 -Djava.awt.headless=true -XX:+UseG1GC -Djava.endorsed.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre/jre/lib/endorsed:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre/lib/endorsed:/opt/openhab/runtime/lib/endorsed -Djava.ext.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre/jre/lib/ext:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre/lib/ext:/opt/openhab/runtime/lib/ext -Dkaraf.instances=/opt/openhab/runtime/instances -Dkaraf.home=/opt/openhab/runtime -Dkaraf.base=/opt/openhab/userdata -Dkaraf.data=/opt/openhab/userdata -Dkaraf.etc=/opt/openhab/userdata/etc -Dkaraf.restart.jvm.supported=true -Djava.io.tmpdir=/opt/openhab/userdata/tmp -Djava.util.logging.config.file=/opt/openhab/userdata/etc/java.util.logging.properties -Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=true -classpath /opt/openhab/runtime/lib/boot/org.apache.karaf.diagnostic.boot-4.0.8.jar:/opt/openhab/runtime/lib/boot/org.apache.karaf.jaas.boot-4.0.8.jar:/opt/openhab/runtime/lib/boot/org.apache.karaf.main-4.0.8.jar:/opt/openhab/runtime/lib/boot/org.osgi.core-6.0.0.jar org.apache.karaf.main.Main

What am I missing here?

Can you look at the output of

sudo netstat -apn | grep 67

I had the exact same error and this is how I found the conflicting package

1 Like