Skip to content

Use resolvectl when no other DNS provider is available#158

Open
gatopeich wants to merge 1 commit intodlenski:masterfrom
gatopeich:master
Open

Use resolvectl when no other DNS provider is available#158
gatopeich wants to merge 1 commit intodlenski:masterfrom
gatopeich:master

Conversation

@gatopeich
Copy link

This allows use of --domains-vpn-dns in Ubuntu out of the box without additional software.

Addresses issue #157

This allows use of --domains-vpn-dns in Ubuntu out of the box without additional software.
@gmacon
Copy link
Collaborator

gmacon commented Jun 17, 2025

Instead of doing this, you should add resolvectl as a provider.

(I'd actually name the provider resolved or systemd-resolved instead, though.)

Come to think of it, I thought someone had already done this, though. It looks like the code is on the branch Linux_split_DNS_PR118_rework.

@faerics
Copy link

faerics commented Jun 20, 2025

Also it's good to explicitly mention that:

  • no action needed on disconnect with this approach
  • there's --no-ns-hosts option and one must use dns IPs in that case (no tun0.dns0 available)

Comment on lines +255 to +257
print(subprocess.run(['resolvectl', 'dns', 'tun0', *map(str, env.dns)]), file=stderr)
for domain in args.vpn_domains:
print(subprocess.run(['resolvectl', 'domain', 'tun0', domain]), file=stderr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode tun0. Use env.tundev

if 'domain_vpn_dns' not in providers:
print("WARNING: no split dns provider available; can't split dns", file=stderr)
print("WARNING: no split dns provider available; trying resolvectl...", file=stderr)
print(subprocess.run(['resolvectl', 'dns', 'tun0', *map(str, env.dns)]), file=stderr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolvectl only exists and works on Linux systems running systemd-resolved.

It should not be used as a catch-all/fallback. Instead, please create a SplitDnsProvider subclass, and plug in that provider on systems where it makes sense. The availability check might consist of running resolvectl status and parsing its output.

Comment on lines +256 to +257
for domain in args.vpn_domains:
print(subprocess.run(['resolvectl', 'domain', 'tun0', domain]), file=stderr)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also does the wrong thing when you provide multiple domains. by calling the command repeatedly, you overwrite the previous domain rather than appending more domains to the list. instead of looping, just set all the domains at once in a single step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants