Multiple stubby instances?

I have two internal networks, and each network needs a different upstream DNS server. I have two DNSMASQ instances, each one configured to serve one network and use a different upstream DNS; this is working as expected.

Now, I have moved one network to DNSMASQ + STUBBY, so all the upstream DNS servers are configured on STUBBY, and again this is working as expected. However, in order to move the second network to DNSMASQ + STUBBY, I need to configure a second STUBBY instance.

Is this possible? How can I configure it? Thanks!

Stumbled upon this whilst searching for answers to the same question ("can I run mutiple instances of STUBBY?"). I've ended up using DNSMASQ+STUBBY for one network and DNSMASQ+UNBOUND for the other. Not sure whether that's the best way of doing things, but it seems to work for now...

1 Like

The current init script for Stubby does not support multiple instances.

2 Likes

was looking for this, i know we can start second instance stubby with /usr/sbin/stubby -g -C example.conf on different ip and/or port but process start owned by root, is there a simple way to start process as correct user (stubby)??

my specific need is to have two stubby instances on localhost with different port, one with cloudflare#5453 and other with google#5553, so i can specify in my config what to use:

cat /etc/config/dhcp

...
list server '127.0.0.1#5453'
list server '0::1#5453'
list server '/google.com/127.0.0.1#5553'
...

so after a bit of reading here and here, as vgaetera pointed out, creating a second init did the trick for me:

root@router:/etc/config# cat /etc/init.d/stubby2 

#!/bin/sh /etc/rc.common

USE_PROCD=1

START=31
STOP=51

stubby="/usr/sbin/stubby"
stubby_init="/etc/init.d/stubby2"
config_file="/etc/config/stubby2"
stubby_config_dir="/var/etc/stubby"
stubby_config="$stubby_config_dir/stubby2.yml"
stubby_pid_file="/var/run/stubby2.pid"

start_service() {

  mkdir -p "$stubby_config_dir"

  cp "$config_file" "$stubby_config"

  chown stubby:stubby "$stubby_config"
  chmod 0400 "$stubby_config"
  
  procd_open_instance "stubby"
  
  procd_set_param command "$stubby" -C "$stubby_config"
  
  procd_set_param respawn
  procd_set_param file "$stubby_config"
  procd_set_param stdout 1
  procd_set_param stderr 1
  procd_set_param pidfile "$stubby_pid_file"
  procd_set_param user stubby
  procd_close_instance
}

service_triggers()
{
    local trigger
    local delay

    trigger="$(uci_get stubby global trigger)"
    delay="$(uci_get stubby global triggerdelay "2")"

    if [ "$trigger" != "none" ] && [ "$trigger" != "timed" ]; then
        PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
        procd_add_interface_trigger "interface.*.up" "$trigger" "$stubby_init" start
    fi
    procd_add_reload_trigger "stubby"
}

pretty sure that the best solution would be to make stubby init read multiple config files, but i have no idea how to do it. @eduperez bit late and not so clean solution but may work for your needs.

4 Likes

Stubby package maintainer here. Patches to allow multiple instances will be gratefully accepted.

4 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.