unbound v1.6.0 python module on debian 9

I’m trying to set up a server running unbound and a python script. This is working OK on an older server running version 1.4.2. On the newer one, I can’t seem to get unbound to see the python script dependencies. I do recall on the old server, this was because chroot was enabled. Once I disabled it in the config file via chroot: “”, it was fine. It’s disabled on the new one too, but still doesn’t seem to help. If I symlink the requested file from /usr/lib/python2.7/dist-packages/unboundpython.py to /etc/unbound/, that resolves that error, but more come up because of course it can’t see the other libraries. This leads me to believe that unbound isn’t looking out of /etc/unbound/ even though chroot is disabled. Is there something else I’m missing?

Hi Christopher,

I’m trying to set up a server running unbound and a python script. This is working OK on an older server running version 1.4.2. On the newer one, I can’t seem to get unbound to see the python script dependencies. I do recall on the old server, this was because chroot was enabled. Once I disabled it in the config file via chroot: “”, it was fine. It’s disabled on the new one too, but still doesn’t seem to help. If I symlink the requested file from /usr/lib/python2.7/dist-packages/unboundpython.py to /etc/unbound/, that resolves that error, but more come up because of course it can’t see the other libraries. This leads me to believe that unbound isn’t looking out of /etc/unbound/ even though chroot is disabled. Is there something else I’m missing?

I am assuming that you want to use a python script with unbound's python
module.

I see that when initializing the python module, unbound appends to the
sys path also the directory reported by Python as the
"platform-dependent include directory" [1].

You can find that directory by starting up the Python interpreter (the
same that unbound will also use; in case of Python virtual environments)
and typing:
  >> import distutils.sysconfig
  >> distutils.sysconfig.get_python_lib(1,0)
  '/usr/local/lib/python2.7/site-packages' (in my case)

As a side note you can also achieve the same with chroot enabled but
then you would need to link the same python directory structure inside
the chroot in order for unbound to find the libraries.

[1]
https://docs.python.org/3.7/distutils/apiref.html?highlight=get_python_lib#distutils.sysconfig.get_python_lib

-- George

Thanks for the reply George. When I run what you suggested, I see /usr/lib/python2.7/dist-packages, and the unboundmodule.py is indeed in there. If I run my python script on it’s own from my shell, it works fine. unbound itself still does not see it, nor any of the other dependencies in that directory. Any idea why this might be?

Hi Christopher,

What is the error you are getting from unbound?
Can you share some bits of your configuration file? I am mainly
interested in the following options:
  chroot:
  directory:
  module-config:
  python-script:

-- George

This is what I have:

server:
verbosity: 1
statistics-cumulative: “yes”
extended-statistics: “yes”
num-threads: 2
interface: “0.0.0.0”
interface: “::0”
interface-automatic: yes
outgoing-port-permit: “32768-65535”
outgoing-port-avoid: “0-32767”
chroot: “”
root-hints: “/etc/unbound/root.hints”
module-config: “validator python iterator”
directory: “/etc/unbound”
cache-max-ttl: 300
log-queries: no
do-not-query-localhost: no
include: /etc/unbound/unbound.local.d/.conf
python:
python-script: “/etc/unbound/dns-backend.py”
remote-control:
control-enable: yes
include: "/etc/unbound/unbound.conf.d/
.conf"

Here’s what I see when I try to run unbound:

unbound -dv -c unbound.conf
[1540500365] unbound[18398:0] notice: Start of unbound 1.6.0.
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named ‘unboundmodule’

However, it’s there:

ll /usr/lib/python2.7/dist-packages/ | grep unbound
-rw-r–r-- 1 root root 102230 Aug 27 2017 unboundmodule.py
-rw-r–r-- 1 root root 85737 Oct 19 15:05 unboundmodule.pyc
-rw-r–r-- 1 root root 36348 Aug 27 2017 unbound.py
-rw-r–r-- 1 root root 39760 Oct 19 15:05 unbound.pyc
-rw-r–r-- 1 root root 80016 Aug 27 2017 _unbound.x86_64-linux-gnu.so

Hello,

Did you try:

apt-get install python3-unbound

On Debian9 Unbound uses python3 iirc.

Hi Christopher,

The only way that I can reproduce the same unbound output is by
removing/renaming the file so that unbound cannot find it.

Your configuration seems correct but maybe some of the included
configurations introduce dubious options?

Also, do you use a packaged version of unbound or you compile your own?

-- George

If I install the same python3 dependencies, the problem goes away. However, my python script is now throwing errors since it doesn’t seem to be python3 compatible.

I’m using the packaged version available for debian 9. I guess it’s compiled to use python3.