jeessy2/ddns-go · error
找不到网卡 %s: %v
Error message
找不到网卡 %s: %v
What it means
GetLocalAddrFromInterface looks up the interface by name with net.InterfaceByName; when no interface with that name exists on the host, the OS lookup fails and this error wraps that failure with a Chinese message meaning 'network interface <name> not found'. It is used by CreateHTTPClientWithInterface to resolve the bind IP for the interface-bound HTTP client.
Source
Thrown at util/http_client_util.go:101
ExpectContinueTimeout: 1 * time.Second,
}
// insecureSkipVerify 全局TLS验证跳过标志
var insecureSkipVerify bool
// CreateHTTPClient Create Default HTTP Client
func CreateHTTPClient() *http.Client {
return &http.Client{
Timeout: 30 * time.Second,
Transport: defaultTransport,
}
}
// GetLocalAddrFromInterface 根据网卡名称获取本地IP地址
func GetLocalAddrFromInterface(ifaceName string) (string, error) {
iface, err := net.InterfaceByName(ifaceName)
if err != nil {
return "", fmt.Errorf("找不到网卡 %s: %v", ifaceName, err)
}
addrs, err := iface.Addrs()
if err != nil {
return "", fmt.Errorf("获取网卡 %s 地址失败: %v", ifaceName, err)
}
for _, addr := range addrs {
if ipNet, ok := addr.(*net.IPNet); ok && ipNet.IP.IsGlobalUnicast() {
return ipNet.IP.String(), nil
}
}
return "", fmt.Errorf("网卡 %s 没有可用的单播地址", ifaceName)
}
// CreateHTTPClientWithInterface 创建绑定指定网卡的HTTP客户端
func CreateHTTPClientWithInterface(ifaceName string) *http.Client {
if ifaceName == "" {
return CreateHTTPClient()
}View on GitHub (pinned to 5874c2e666)
Solutions
- List actual interface names (net.Interfaces(), or `ip link`) and correct the configured name
- Make the interface name configurable per environment instead of hardcoding
- Note CreateHTTPClientWithInterface already falls back to the default client on this error — check logs for '绑定网卡失败' to confirm the fallback happened
- Create the missing interface (bring up the VPN/tunnel) if the app expects it
Example fix
// before
client := util.CreateHTTPClientWithInterface("eth0") // host uses ens33
// after
ifaces, _ := net.Interfaces() // inspect names, then:
client := util.CreateHTTPClientWithInterface("ens33") Defensive patterns
Strategy: validation
Validate before calling
func ifaceExists(name string) bool {
_, err := net.InterfaceByName(name)
return err == nil
}
// guard: if !ifaceExists(cfg.Interface) { fail fast or use default client } Try / catch
func safeClientWithInterface(name string) *http.Client {
if _, err := net.InterfaceByName(name); err != nil {
log.Printf("interface %q not found: %v; using default client", name, err)
return util.CreateHTTPClient()
}
return util.CreateHTTPClientWithInterface(name)
} Prevention
- Discover interface names at runtime (net.Interfaces()) instead of hardcoding
- Use per-environment configuration for the interface name (host NIC names differ: eth0/ens33/en0)
- Fail fast at startup if the configured interface does not exist, rather than silently falling back
- Remember CreateHTTPClientWithInterface silently falls back to the default client — watch logs for '绑定网卡失败'
When it happens
Trigger: Calling GetLocalAddrFromInterface(name) or CreateHTTPClientWithInterface(name) with a name that does not match any interface on the machine (typos, Windows names like '以太网' vs Linux 'eth0', renamed interfaces).
Common situations: Config written for one machine deployed to another with different NIC names (eth0 vs ens33 vs en0); container names differ from host names; interface renamed by systemd predictable naming; missing netdev (VPN not up).
Related errors
- interface %s not found: %v
- get interface %s addresses failed: %v
- 监听端口发生异常, 请检查端口是否被占用! %s
- 请求 dnsla 失败: %w
- 读取 dnsla 响应失败: %w
AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03).
Data as JSON: /api/errors/489b5af4f18d4f9f.
Report an issue: GitHub.