Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func init() {
startCmd.Flags().BoolVar(&startCmdArgs.Network.Address, "network-address", false, "assign reachable IP address to the VM")
startCmd.Flags().StringVar(&startCmdArgs.Network.Mode, "network-mode", "shared", "network mode (shared, bridged)")
startCmd.Flags().StringVar(&startCmdArgs.Network.BridgeInterface, "network-interface", "en0", "host network interface to use for bridged mode")
startCmd.Flags().BoolVar(&startCmdArgs.Network.PreferredRoute, "network-preferred-route", false, "use the assigned IP address as the preferred route for the VM (implies --network-address)")

// vm type
if util.MacOS13OrNewer() {
Expand Down Expand Up @@ -535,6 +536,9 @@ func prepareConfig(cmd *cobra.Command) {
if !cmd.Flag("network-interface").Changed {
startCmdArgs.Network.BridgeInterface = current.Network.BridgeInterface
}
if !cmd.Flag("network-preferred-route").Changed {
startCmdArgs.Network.PreferredRoute = current.Network.PreferredRoute
}
if util.MacOS13OrNewer() {
if !cmd.Flag("vm-type").Changed {
startCmdArgs.VMType = current.VMType
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Network struct {
HostAddresses bool `yaml:"hostAddresses"`
Mode string `yaml:"mode"` // shared, bridged
BridgeInterface string `yaml:"interface"`
PreferredRoute bool `yaml:"preferredRoute"`
}

// Mount is volume mount
Expand Down
5 changes: 5 additions & 0 deletions embedded/defaults/colima.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ network:
# Default: en0
interface: en0

# Use the assigned IP address as the preferred route for the VM.
# Note: this only has an effect when `address` is set to true.
# Default: false
preferredRoute: false

# Custom DNS resolvers for the virtual machine.
#
# EXAMPLE
Expand Down
3 changes: 2 additions & 1 deletion environment/vm/lima/limautil/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
const NetInterface = "col0"

// network metric for the route
const NetMetric = 300
const NetMetric uint32 = 300
const NetMetricPreferred uint32 = 100

// IPAddress returns the ip address for profile.
// It returns the PTP address if networking is enabled or falls back to 127.0.0.1.
Expand Down
8 changes: 6 additions & 2 deletions environment/vm/lima/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,16 @@ func newConf(ctx context.Context, conf config.Config) (l limaconfig.Config, err

reachableIPAddress := true
if conf.Network.Address {
metric := limautil.NetMetric
if conf.Network.PreferredRoute {
metric = limautil.NetMetricPreferred
}
// vmnet is always used for incus runtime or bridged mode
if l.VMType == limaconfig.VZ && conf.Runtime != incus.Name && conf.Network.Mode != "bridged" {
l.Networks = append(l.Networks, limaconfig.Network{
VZNAT: true,
Interface: limautil.NetInterface,
Metric: limautil.NetMetric,
Metric: metric,
})
} else {
reachableIPAddress, _ = ctx.Value(daemon.CtxKey(vmnet.Name)).(bool)
Expand All @@ -155,7 +159,7 @@ func newConf(ctx context.Context, conf config.Config) (l limaconfig.Config, err
l.Networks = append(l.Networks, limaconfig.Network{
Socket: socketFile,
Interface: limautil.NetInterface,
Metric: limautil.NetMetric,
Metric: metric,
})

return nil
Expand Down