jeessy2/ddns-go · error
获取网卡 %s 地址失败: %v
Error message
获取网卡 %s 地址失败: %v
What it means
GetLocalAddrFromInterface calls iface.Addrs() to enumerate the interface's addresses; if the OS returns an error at that point this error ('failed to get addresses for interface <name>') wraps it. This happens after the interface was found, so it indicates a system-level failure retrieving the address list rather than a bad name.
Source
Thrown at util/http_client_util.go:105
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()
}
localIP, err := GetLocalAddrFromInterface(ifaceName)
if err != nil {
Log("绑定网卡失败, 将使用默认网卡. 网卡: %s, 错误: %v", ifaceName, err)
return CreateHTTPClient()View on GitHub (pinned to 5874c2e666)
Solutions
- Retry the call — this is often transient (interface state changed momentarily)
- Verify the interface still exists and the process has permission to read network state
- Check for seccomp/AppArmor/container policies restricting netlink socket usage
- If persistent, recreate the network namespace/interface or restart networking on the host
Defensive patterns
Strategy: retry
Validate before calling
func canReadAddrs(name string) error {
iface, err := net.InterfaceByName(name)
if err != nil { return err }
_, err = iface.Addrs()
return err
}
// if err != nil, retry with backoff before creating the client Try / catch
var client *http.Client
var err error
for i := 0; i < 3; i++ {
if _, err = util.GetLocalAddrFromInterface(ifaceName); err == nil {
client = util.CreateHTTPClientWithInterface(ifaceName)
break
}
time.Sleep(time.Duration(1<<i) * 100 * time.Millisecond)
}
if err != nil {
log.Printf("giving up binding to %s: %v; using default client", ifaceName, err)
client = util.CreateHTTPClient()
} Prevention
- Treat Addrs() failures as transient and retry with backoff
- Verify container/seccomp policies permit netlink socket operations
- Re-verify the interface still exists if the error persists (it may have been unplugged/renamed)
When it happens
Trigger: Calling GetLocalAddrFromInterface/CreateHTTPClientWithInterface when net.Interface.Addrs() fails — e.g. permission issues reading interface data, netlink/socket errors, or the interface disappearing between the name lookup and the address query (hot-unplug, container teardown).
Common situations: Restricted containers/seccomp setups blocking netlink operations; NIC removed/rename raced with the lookup; kernel or network namespace issues; rare transient OS errors.
Related errors
- interface %s has no usable %s address
- interface %s has no usable global-unicast address
- 网卡 %s 没有可用的单播地址
- 监听端口发生异常, 请检查端口是否被占用! %s
- 请求 dnsla 失败: %w
AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03).
Data as JSON: /api/errors/70e044daf0cf4cab.
Report an issue: GitHub.