# Multiple stubby instances?

**URL:** <https://forum.openwrt.org/t/multiple-stubby-instances/49546>\
**Category:** Network and Wireless Configuration\
**Created:** [December 1, 2019, 11:33pm UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546 "2019-12-01T23:33:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduperez](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eduperez/32/2066_2.png) [@eduperez](https://forum.openwrt.org/u/eduperez)\
**Post date:** [December 1, 2019, 11:33pm UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546/1 "2019-12-01T23:33:57Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![tectonic](https://forum.openwrt.org/letter_avatar/tectonic/32/6_449c533f586939b6e5f246632a46421f.png) [@tectonic](https://forum.openwrt.org/u/tectonic)\
**Post date:** [July 23, 2020, 7:32am UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546/2 "2020-07-23T07:32:10Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![vgaetera](https://forum.openwrt.org/user_avatar/forum.openwrt.org/vgaetera/32/113586_2.png) [@vgaetera](https://forum.openwrt.org/u/vgaetera)\
**Post date:** [July 23, 2020, 5:41pm UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546/3 "2020-07-23T17:41:09Z")

</div>

The current [init script for Stubby](https://github.com/openwrt/packages/blob/master/net/stubby/files/stubby.init) does not support multiple instances.

---

<div class="post-metadata">

**Author:** ![jesanor](https://forum.openwrt.org/letter_avatar/jesanor/32/6_449c533f586939b6e5f246632a46421f.png) [@jesanor](https://forum.openwrt.org/u/jesanor)\
**Post date:** [July 24, 2020, 2:31am UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546/4 "2020-07-24T02:31:39Z")

</div>

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)??

---

<div class="post-metadata">

**Author:** ![jesanor](https://forum.openwrt.org/letter_avatar/jesanor/32/6_449c533f586939b6e5f246632a46421f.png) [@jesanor](https://forum.openwrt.org/u/jesanor)\
**Post date:** [July 24, 2020, 7:09am UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546/5 "2020-07-24T07:09:47Z")

</div>

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](https://openwrt.org/docs/guide-developer/procd-init-scripts) and [here](https://github.com/openwrt/packages/blob/master/net/stubby/files/stubby.init), 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.

---

<div class="post-metadata">

**Author:** ![wunderspud](https://forum.openwrt.org/letter_avatar/wunderspud/32/6_449c533f586939b6e5f246632a46421f.png) [@wunderspud](https://forum.openwrt.org/u/wunderspud)\
**Post date:** [July 24, 2020, 8:06am UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546/7 "2020-07-24T08:06:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.openwrt.org/uploads/default/original/3X/7/4/740520c71f00039bbf001045c682f0ecb25e905a.png) [@system](https://forum.openwrt.org/u/system)\
**Post date:** [August 3, 2020, 8:06am UTC](https://forum.openwrt.org/t/multiple-stubby-instances/49546/8 "2020-08-03T08:06:45Z")

</div>

Closed on August 3, 2020, 8:06am UTC

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