var lastErr error
for i := 0; i < cfg.attempts; i++ {
for _, server := range cfg.servers {
- server = JoinHostPort(server, "53")
msg, err := exchange(ctx, server, name, qtype)
if err != nil {
lastErr = &DNSError{
{
name: "golang.org",
lines: []string{"nameserver 8.8.8.8"},
- servers: []string{"8.8.8.8"},
+ servers: []string{"8.8.8.8:53"},
},
{
name: "",
{
name: "www.example.com",
lines: []string{"nameserver 8.8.4.4"},
- servers: []string{"8.8.4.4"},
+ servers: []string{"8.8.4.4:53"},
},
}
)
var (
- defaultNS = []string{"127.0.0.1", "::1"}
+ defaultNS = []string{"127.0.0.1:53", "[::1]:53"}
getHostname = os.Hostname // variable for testing
)
type dnsConfig struct {
- servers []string // servers to use
+ servers []string // server addresses (in host:port form) to use
search []string // suffixes to append to local name
ndots int // number of dots in name to trigger absolute lookup
timeout time.Duration // wait before giving up on a query, including retries
// just an IP address. Otherwise we need DNS
// to look it up.
if parseIPv4(f[1]) != nil {
- conf.servers = append(conf.servers, f[1])
+ conf.servers = append(conf.servers, JoinHostPort(f[1], "53"))
} else if ip, _ := parseIPv6(f[1], true); ip != nil {
- conf.servers = append(conf.servers, f[1])
+ conf.servers = append(conf.servers, JoinHostPort(f[1], "53"))
}
}
{
name: "testdata/resolv.conf",
want: &dnsConfig{
- servers: []string{"8.8.8.8", "2001:4860:4860::8888", "fe80::1%lo0"},
+ servers: []string{"8.8.8.8:53", "[2001:4860:4860::8888]:53", "[fe80::1%lo0]:53"},
search: []string{"localdomain"},
ndots: 5,
timeout: 10 * time.Second,
{
name: "testdata/domain-resolv.conf",
want: &dnsConfig{
- servers: []string{"8.8.8.8"},
+ servers: []string{"8.8.8.8:53"},
search: []string{"localdomain"},
ndots: 1,
timeout: 5 * time.Second,
{
name: "testdata/search-resolv.conf",
want: &dnsConfig{
- servers: []string{"8.8.8.8"},
+ servers: []string{"8.8.8.8:53"},
search: []string{"test", "invalid"},
ndots: 1,
timeout: 5 * time.Second,
timeout: 5 * time.Second,
attempts: 2,
lookup: []string{"file", "bind"},
- servers: []string{"169.254.169.254", "10.240.0.1"},
+ servers: []string{"169.254.169.254:53", "10.240.0.1:53"},
search: []string{"c.symbolic-datum-552.internal."},
},
},