- Installation
- Remote Control on Unbound
- Execute command
- Loading zone from YAML file
- Loading zone from "LocalZone" object
- Execute bulk command
This module can be installed from pypi website.
This command will install the module with yaml support for loading zone data.
pip install unbound_console[yaml]
If loading a zone using yaml is not required use the following command, zone data can instead be loaded through the LocalZone
object:
pip install unbound_console
Before to use this utility. You must activate the remote control on your unbound server. See config file example.
You can execute commands with the function send_command
. See nlnetlabs documentations for the full list of available commands.
- Import the module in your code
from unbound_console import RemoteControl
An asyncio implementation is available, use
RemoteControlAsync
instead.
- Configure the remote control client with tls support. You can also provide a unix socket
unix_sock="/var/run/unbound-console.sock"
.
rc = RemoteControl(host="127.0.0.1", port=8953,
server_cert = "/etc/unbound/unbound_server.pem",
client_cert= "/etc/unbound/unbound_control.pem",
client_key= "/etc/unbound/unbound_control.key")
- Execute a command and get output
o = rc.send_command(cmd="status")
print(o)
YAML zone definition example:
This requires installing unbound_console with yaml support
zone:
name: home.
type: static
records:
- "router.home. 86400 IN A 192.168.0.1"
- "192.168.0.1 86400 IN PTR router.test."
Call load_zone
with the yaml file to load-it in your unbound server.
o = rc.load_zone(zone_data='<yaml content>')
print(o)
Example loading from a LocalZone
object:
from unbound_console import LocalZone
zone = LocalZone(
name="home",
type="static",
records=[
"router.home. 86400 IN A 192.168.0.1",
"192.168.0.1 86400 IN PTR router.test.",
],
)
o = rc.load_zone(zone_data=zone)
print(o)
domains_bulk = []
domains_bulk.append( "www.google.com always_nxdomain")
o = rc.send_command(cmd="local_zones", data_list=domains_bulk)
print(o)