Skip to content

Support --network-cidr for vfkit and krunkit drivers #22828

@nirs

Description

@nirs

The problem

vmnet-helper v0.12.0 will change the default network, matching the system defaults. If --start-address, --end-address, and --subnet-mask are not specified, you get the default network 192.168.64.0/24 instead of the legacy network 192.168.105.0/24.

If the default network is already reserved by another program (e.g Apple container), we will get the next available network (typically 192.168.65.0/24).

This does not affect minikube since we discover the VM IP address. It may affect users that hard code the network address in configuration, or depend on other programs (e.g. lima) that use the legacy network.

See nirs/vmnet-helper#123

Adding a network CIDR option

If users need to control the network used by minikube, they do not have a way to configure minikube. We can add a single --network-cidr flag:

vfkit driver

minikube start --driver vfkit --network vmnet-shared --network-cidr 192.168.105.0/24

krunkit driver

minikube start --driver krunkit --network-cidr 192.168.105.0/24

Config

To make it easy to configure many clusters, we want to add the option to minikube config.

minikube config set network-cidr 192.168.105.0/24

Implemention

Minikube will parse the CIDR notation using Go's standard library and pass
the right flags to vmnet-helper:

_, network, err := net.ParseCIDR("192.168.105.0/24")

if len(network.IP) != net.IPv4len {
	return fmt.Errorf("vmnet requires an IPv4 CIDR, got %q", cidr)
}

// Start address (gateway): 192.168.105.1
start := make(net.IP, net.IPv4len)
copy(start, network.IP)
start[3] |= 1

// End address: 192.168.105.254
end := make(net.IP, net.IPv4len)
for i := range end {
	end[i] = network.IP[i] | ^network.Mask[i]
}
end[3] &= 0xfe

// Subnet mask: 255.255.255.0
mask := net.IP(network.Mask)
start-address: "192.168.105.1"
end-address: "192.168.105.254"
subnet-mask: "255.255.255.0"

vmnet requires specifying the host address 192.168.105.1 and rejects the network
address 192.168.105.0. Using CIDR notation we improve the user experience by
hiding these details.

Notes

  • The krunkit driver uses --network vmnet-shared implicitly - we may want to change it to accept --network vmnet-shared and reject other values.
  • The --network-cidr option is generic and could be supported by other drivers.
  • The option is not compatible with vmnet-helper --network option, that we want to use on macOS 26 if vmnet-broker is installed.
  • If the network is reserved by another program (e.g. Apple container) minikube start will fail. Letting vmnet pick the network is the most reliable way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions