@@ -5,6 +5,7 @@ package dns
5
5
import (
6
6
"fmt"
7
7
"net"
8
+ "runtime"
8
9
"strings"
9
10
10
11
"github.com/lima-vm/lima/pkg/limayaml"
@@ -63,12 +64,31 @@ func newStaticClientConfig(ips []string) (*dns.ClientConfig, error) {
63
64
}
64
65
65
66
func NewHandler (opts HandlerOptions ) (dns.Handler , error ) {
66
- cc , err := dns .ClientConfigFromFile ("/etc/resolv.conf" )
67
- if err != nil {
68
- logrus .WithError (err ).Warnf ("failed to detect system DNS, falling back to %v" , defaultFallbackIPs )
69
- cc , err = newStaticClientConfig (defaultFallbackIPs )
70
- if err != nil {
71
- return nil , err
67
+ var cc * dns.ClientConfig
68
+ var err error
69
+ if len (opts .UpstreamServers ) == 0 {
70
+ if runtime .GOOS != "windows" {
71
+ cc , err = dns .ClientConfigFromFile ("/etc/resolv.conf" )
72
+ if err != nil {
73
+ logrus .WithError (err ).Warnf ("failed to detect system DNS, falling back to %v" , defaultFallbackIPs )
74
+ cc , err = newStaticClientConfig (defaultFallbackIPs )
75
+ if err != nil {
76
+ return nil , err
77
+ }
78
+ }
79
+ } else {
80
+ // For windows, the only fallback addresses are defaultFallbackIPs
81
+ // since there is no /etc/resolv.conf
82
+ cc , err = newStaticClientConfig (defaultFallbackIPs )
83
+ if err != nil {
84
+ return nil , err
85
+ }
86
+ }
87
+ } else {
88
+ if cc , err = newStaticClientConfig (opts .UpstreamServers ); err != nil {
89
+ if cc , err = newStaticClientConfig (defaultFallbackIPs ); err != nil {
90
+ return nil , err
91
+ }
72
92
}
73
93
}
74
94
clients := []* dns.Client {
0 commit comments