Skip to content

Add query_interface configuration for binding IP queries to specific network interfaces#302

Draft
Claude wants to merge 2 commits intomasterfrom
claude/add-query-ip-address-interface
Draft

Add query_interface configuration for binding IP queries to specific network interfaces#302
Claude wants to merge 2 commits intomasterfrom
claude/add-query-ip-address-interface

Conversation

@Claude
Copy link
Copy Markdown

@Claude Claude AI commented Mar 9, 2026

Users with multiple WAN connections need to query their public IP through a specific interface, particularly when default routes go through CGNAT while backup routes have public IPs.

Changes

  • Configuration: Added query_interface field to Settings struct for specifying which network interface to bind IP queries to

  • Network binding: Modified getIPOnline() to bind HTTP dialer to local address on specified interface:

    • Looks up interface by name via net.InterfaceByName()
    • Finds suitable local IP matching protocol version (IPv4/IPv6)
    • Sets net.Dialer.LocalAddr to bind TCP connection to that interface
  • Documentation: Added section explaining query_interface vs ip_interface distinction with dual-WAN example

Usage

{
  "ip_urls": ["https://api.ipify.org/"],
  "query_interface": "wan0",
  "ip_type": "IPv4"
}

When set, GoDNS queries public IP through the specified interface rather than default route, ensuring the returned IP reflects the actual reachable address.

Note: query_interface binds the HTTP request to an interface, while ip_interface reads IP directly from local interface without external requests.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add a way to query IP address through a specific interface</issue_title>
<issue_description>Describe the bug

I have two uplinks in my system: wan0 and wan1. wan1 is wired, but is behind a CGNAT. wan0 is a backup link to a sattelite, but I get a dynamic IP address to use with this link that's not behind a CGNAT. The routes are set up such that by default packets are routed through (the CGNATed) wan1.

I would like godns to query the IP address through wan0 link specifically, so that it obtains the IP address through which the machine is actually reachable.

The frequency of this issue

  • This issue is easy to reproduce.
  • This issue is not easy to reproduce. -- requires multiple uplinks

Steps to Reproduce

Obtain two interfaces with a public internet access. Set up the routes such that they read like this:

$ ip route
default dev wan1 proto static scope link metric 1000 
default dev wan0 proto static scope link metric 1001 
...

Your GoDNS configuration

{
  "ip_url": "https://api.ipify.org/",
  "ip_type": "IPv4",
  "debug_info": true,
  "interval": 3600
}

Expected behavior

It should be possible to ask godns to make a request through wan0 specifically (this can be done by binding the TCP socket I believe) so that the machine making the request is actually reachable over the obtained IP address.

Screenshots

N/A

Environment (please complete the following information):

  • DNS Provider: N/A
  • OS: Linux

Additional context
Add any other context about the problem here.</issue_description>

Comments on the Issue (you are @claude[agent] in this section)

@TimothyYe Thanks for your feedback, I think it's possible. Let me figure out the solution.

…ork interfaces

Co-authored-by: TimothyYe <860685+TimothyYe@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Add a way to query IP address through specific interface Add query_interface configuration for binding IP queries to specific network interfaces Mar 9, 2026
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.

Add a way to query IP address through a specific interface

2 participants