Skip to content

Commit

Permalink
Merge pull request #570 from rancher-sandbox/default-interface
Browse files Browse the repository at this point in the history
Use DNS and proxy settings from first interface with an IPv4 address
  • Loading branch information
AkihiroSuda authored Jan 21, 2022
2 parents 53b78dc + 29e63be commit f35a762
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DNS over tcp is rarely used. It is usually only used either when user explicitly

During initial cloud-init bootstrap, `iptables` may not yet be installed. In that case the repo server is determined using the slirp DNS. After `iptables` has been installed, the forwarding rule is applied, switching over to the hostagent DNS.

If `useHostResoler` is false, then DNS servers can be configured manually in `lima.yaml` via the `dns` setting. If that list is empty, then Lima will either use the slirp DNS (on Linux), or the nameservers from the `en0` host interface (on macOS).
If `useHostResoler` is false, then DNS servers can be configured manually in `lima.yaml` via the `dns` setting. If that list is empty, then Lima will either use the slirp DNS (on Linux), or the nameservers from the first host interface in service order that has an assigned IPv4 address (on macOS).

## `vde_vmnet` (192.168.105.0/24)

Expand Down
7 changes: 4 additions & 3 deletions pkg/limayaml/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ hostResolver:
# If useHostResolver is false, then the following rules apply for configuring dns:
# Explicitly set DNS addresses for qemu user-mode networking. By default qemu picks *one*
# nameserver from the host config and forwards all queries to this server. On macOS
# Lima adds the nameservers configured for the "en0" interface to the list. In case this
# still doesn't work (e.g. VPN setups), the servers can be specified here explicitly.
# If nameservers are specified here, then the "en0" configuration will be ignored.
# Lima adds the nameservers configured for the first host interface in service order,
# that has an IPv4 address, to the list. In case this still doesn't work (e.g. VPN
# setups), the servers can be specified here explicitly. If nameservers are specified
# here, then the configuration from network preferences will be ignored.
# dns:
# - 1.1.1.1
# - 1.0.0.1
Expand Down
16 changes: 7 additions & 9 deletions pkg/osutil/dns_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ func DNSAddresses() ([]string, error) {
}
var addresses []string
if len(nwData) > 0 {
// Return DNS addresses from en0 interface
// Return DNS addresses from the first interface that has an IPv4 address.
// The networks are in service order already.
for _, nw := range nwData {
if nw.Interface == "en0" {
if len(nw.IPv4.Addresses) > 0 {
addresses = nw.DNS.ServerAddresses
break
}
}
// In case "en0" is not found, use the addresses of the first interface
if len(addresses) == 0 {
addresses = nwData[0].DNS.ServerAddresses
}
}
return addresses, nil
}
Expand All @@ -48,10 +45,11 @@ func ProxySettings() (map[string]string, error) {
}
env := make(map[string]string)
if len(nwData) > 0 {
// In case "en0" is not found, use the proxies of the first interface
proxies := nwData[0].Proxies
// Return proxy settings from the first interface that has an IPv4 address.
// The networks are in service order already.
var proxies sysprof.Proxies
for _, nw := range nwData {
if nw.Interface == "en0" {
if len(nw.IPv4.Addresses) > 0 {
proxies = nw.Proxies
break
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/sysprof/network_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ type SPNetworkDataType struct {
type NetworkDataType struct {
DNS DNS `json:"DNS"`
Interface string `json:"interface"`
IPv4 IPv4 `json:"IPv4,omitempty"`
Proxies Proxies `json:"Proxies"`
}

type DNS struct {
ServerAddresses []string `json:"ServerAddresses"`
}

type IPv4 struct {
Addresses []string `json:"Addresses,omitempty"`
}

type Proxies struct {
ExceptionList []string `json:"ExceptionList"` // default: ["*.local", "169.254/16"]
FTPEnable string `json:"FTPEnable"`
Expand Down

0 comments on commit f35a762

Please sign in to comment.