folbricht / routedns

DNS stub resolver, proxy and router with support for DoT, DoH, DoQ, and DTLS
BSD 3-Clause "New" or "Revised" License
441 stars 62 forks source link

Request to add the same port to use different upstream #395

Open liang-hiwin opened 1 week ago

liang-hiwin commented 1 week ago

for example:

[listeners.local-dtls]
address = ":853"
server = "block.example.com"
protocol = "dtls"
resolver = "Blockads-cloudflare-dot"           #####Block ads upstream
server-crt = "example-config/server-ec.crt"
server-key = "example-config/server-ec.key"
[listeners.local-dtls]
address = ":853"
server = "no-block.example.com"
protocol = "dtls"
resolver = "no_blockads-cloudflare-dot"           #####Do not block ads and directly forward requests to upstream
server-crt = "example-config/server-ec.crt"
server-key = "example-config/server-ec.key"
folbricht commented 1 week ago

I don't think it's possible exactly like in the example. Though what you should be able to do is setup different interfaces, and then have a listener on each.

liang-hiwin commented 1 week ago

I don't think it's possible exactly like in the example. Though what you should be able to do is setup different interfaces, and then have a listener on each.

I want to use the same port and then decide which upstream to use depending on the domain name

folbricht commented 1 week ago

You can do that much more easily with a single listener that receives the query, then either a router or a blocklist behind it to send it upstream to the right place

liang-hiwin commented 1 week ago

I still don't quite understand how to distinguish them. For example, if I build the dns-over-tls server: no-block.example.com:853, the upstream is clean and does not block ads. However, the upstream of the dns-over-tls server block.example.com:853 with ads removed is the upstream after ads are removed. I don't know how to configure it now.

folbricht commented 1 week ago

Hmm, if you want to have two different listeners on the same host with the client being able to choose, you could setup 2 different interfaces (with different IPs) on the host. So basically address = "<IP1>:853" and address = "<IP2>:853". Then set no-block.example.com -> IP1 and block.example.com -> IP2 to resolve the right IP.

liang-hiwin commented 1 week ago

Hmm, if you want to have two different listeners on the same host with the client being able to choose, you could setup 2 different interfaces (with different IPs) on the host. So basically address = "<IP1>:853" and address = "<IP2>:853". Then set no-block.example.com -> IP1 and block.example.com -> IP2 to resolve the right IP.

I only have one public IP address for the same host, so it’s a bit difficult.

folbricht commented 1 week ago

With DoH it would be possible to do something like that (not implemented yet though), since the HTTP headers which contain the name the client used would be available to the listener.

liang-hiwin commented 1 week ago

With DoH it would be possible to do something like that (not implemented yet though), since the HTTP headers which contain the name the client used would be available to the listener.

Yes doh I can do this using nginx

cbuijs commented 1 week ago

This should work:

[listeners.local-dtls]
address = ":853"
protocol = "dtls"
resolver = "route-queries"
server-crt = "example-config/server-ec.crt"
server-key = "example-config/server-ec.key"

[router.route-queries]
routes = [
    {servername = '^block\.', resolver = "Blockads-cloudflare-dot"},
    {servername = '^no-block\.', resolver = "no_blockads-cloudflare-dot"},
]

Not sure it works with dtls but it does with dot, and doq queries (I use it).

P.S. Make sure your certicate used, have both domains/servernames in it.

liang-hiwin commented 3 days ago

853

Thanks for taking the time to test it.