Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS resolution over specific interface #34818

Closed
daguej opened this issue Aug 18, 2020 · 2 comments
Closed

DNS resolution over specific interface #34818

daguej opened this issue Aug 18, 2020 · 2 comments
Labels
dns Issues and PRs related to the dns subsystem. feature request Issues that request new features to be added to Node.js.

Comments

@daguej
Copy link
Contributor

daguej commented Aug 18, 2020

Is your feature request related to a problem? Please describe.
On a system with multiple network interfaces, I would like to make DNS resolution requests over a specific interface.

I have a problem similar to #14617. Consider a Linux server with 2 interfaces, primary eth0 and a backup internet connection using a LTE modem on eth1. The system's default route is over eth0, and in normal operation all traffic goes over that interface.

If the primary connection is unavailable, I want to be able to make certain requests from my node program over the backup connection. However, the backup connection is metered, so I don't want a systemwide failover; only specific, high-priority requests should go over the backup.

With the appropriate alternate IP routing table and rules configured, this works for TCP sockets if you set localAddress when calling connect(opts) and already know the destination address. However, I need a way to resolve DNS over the backup connection if necessary — and separately from the system's default resolv.conf settings.

Describe the solution you'd like
This could be accomplished similarly to the localAddress option available to TCP sockets. (There's also bind(port, address) available to UDP sockets.)

eg:

const dns = require('dns');
const resolver = new dns.Resolver({ localAddress: '192.168.0.x' });
resolver.setServers(['8.8.8.8']);
resolver.resolve4();

I think this would be as simple as calling ares_set_local_ip4/ares_set_local_ip6 somewhere in cares_wrap.cc.

@daguej
Copy link
Contributor Author

daguej commented Aug 18, 2020

If this is reasonable, I'm happy to take a stab at implementing.

@jasnell jasnell added dns Issues and PRs related to the dns subsystem. feature request Issues that request new features to be added to Node.js. labels Aug 18, 2020
@jasnell
Copy link
Member

jasnell commented Aug 18, 2020

/cc @bnoordhuis

aduh95 pushed a commit to daguej/node that referenced this issue Oct 24, 2020
@aduh95 aduh95 closed this as completed in 3e10ce3 Oct 25, 2020
targos pushed a commit that referenced this issue Nov 3, 2020
Fixes: #34818

PR-URL: #34824
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
targos pushed a commit that referenced this issue Mar 3, 2021
Fixes: #34818

PR-URL: #34824
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
MylesBorins pushed a commit that referenced this issue Apr 6, 2021
Fixes: #34818

PR-URL: #34824
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dns Issues and PRs related to the dns subsystem. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@daguej @jasnell and others