# rpc错误：代码=不可用 描述=连接错误：描述=“传输：拨号时出错：拨号tcp：在8.8.8.8:53上查找myservice：无此主机”

- **ID:** `go/grpc-unavailable-dns-probe`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

DNS服务器无法解析gRPC服务主机名，通常是由于DNS配置错误或服务名称拼写错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **Use the service's IP address directly in the dial string.** (90% 成功率)
   ```
   conn, err := grpc.Dial("10.0.0.5:50051", grpc.WithInsecure())
   ```
2. **Add the hostname to /etc/hosts or use a custom resolver.** (85% 成功率)
   ```
   net.DefaultResolver = &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { d := net.Dialer{}; return d.DialContext(ctx, "udp", "192.168.1.1:53") }}
   ```

## 无效尝试

- **Adding a random retry delay.** — DNS resolution still fails; delay doesn't fix the lookup. (95% 失败率)
- **Changing the DNS server to a public one like 1.1.1.1.** — Public DNS may not have the private service record. (70% 失败率)
