Skip to content

Commit 1cc0288

Browse files
committed
Provide explicit DNS override
In some situations (e.g. VPN) the user may need to explicitly set the DNS addresses; even the fallback to the "en0" settings does not work. This cannot be done in a provisioning script because they run after the boot scripts, but working DNS is required to install additional dependencies. Signed-off-by: Jan Dubois <[email protected]>
1 parent 30cb59c commit 1cc0288

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

pkg/cidata/cidata.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML) error {
8181
args.Networks = append(args.Networks, Network{MACAddress: vde.MACAddress, Name: vde.Name})
8282
}
8383

84-
args.DNSAddresses, err = osutil.DNSAddresses()
85-
if err != nil {
86-
return err
84+
if len(y.DNS) > 0 {
85+
for _, addr := range y.DNS {
86+
args.DNSAddresses = append(args.DNSAddresses, addr.String())
87+
}
88+
} else {
89+
args.DNSAddresses, err = osutil.DNSAddresses()
90+
if err != nil {
91+
return err
92+
}
8793
}
8894

8995
if err := ValidateTemplateArgs(args); err != nil {

pkg/limayaml/default.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ network:
172172
# env:
173173
# KEY: value
174174

175+
# Explicitly set DNS addresses for qemu user-mode networking. By default qemu picks *one*
176+
# nameserver from the host config and forwards all queries to this server. On macOS
177+
# Lima adds the nameservers configured for the "en0" interface to the list. In case this
178+
# still doesn't work (e.g. VPN setups), the servers can be specified here explicitly.
179+
# If nameservers are specified here, then the "en0" configuration will be ignored.
180+
# dns:
181+
# - 1.1.1.1
182+
# - 1.0.0.1
183+
175184
# ===================================================================== #
176185
# END OF TEMPLATE
177186
# ===================================================================== #

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type LimaYAML struct {
2222
PortForwards []PortForward `yaml:"portForwards,omitempty"`
2323
Network Network `yaml:"network,omitempty"`
2424
Env map[string]*string `yaml:"env,omitempty"` // EXPERIMENAL, see default.yaml
25+
DNS []net.IP `yaml:"dns,omitempty"`
2526
}
2627

2728
type Arch = string

0 commit comments

Comments
 (0)