Skip to content

net: add option to make vmnet the default route#1392

Merged
abiosoft merged 3 commits intoabiosoft:mainfrom
sakkyoi:fix-vmnet-route
Sep 8, 2025
Merged

net: add option to make vmnet the default route#1392
abiosoft merged 3 commits intoabiosoft:mainfrom
sakkyoi:fix-vmnet-route

Conversation

@sakkyoi
Copy link
Contributor

@sakkyoi sakkyoi commented Sep 7, 2025

Description

Fix network routing issues when using multiple network interfaces with bridged mode.

Problem

When starting Colima with bridged networking mode, the routing table may not be configured correctly, leading to connectivity issues between containers and the host network.

Example before fix:

$ colima start --network-address --network-mode bridged
$ colima ssh
$ ip route
default via 192.168.5.2 dev eth0 proto dhcp src 192.168.5.1 metric 200 
default via 10.10.20.10 dev col0 proto dhcp src 10.10.20.22 metric 300 
10.10.20.0/24 dev col0 proto kernel scope link src 10.10.20.22 metric 300 
...
if interested in what happens, tcpdumps is here

ping from same subnet (works):

$ tcpdump -i col0 arp or icmp
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on col0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:38:50.223964 IP 10.10.20.20 > 10.10.20.22: ICMP echo request, id 22125, seq 0, length 64
15:38:50.224077 IP 10.10.20.22 > 10.10.20.20: ICMP echo reply, id 22125, seq 0, length 64
...

ping from different subnet (does not work):

$ tcpdump -i col0 arp or icmp
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on col0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:40:24.155883 IP 10.10.11.27 > 10.10.20.22: ICMP echo request, id 51225, seq 0, length 64
15:40:25.160998 IP 10.10.11.27 > 10.10.20.22: ICMP echo request, id 51225, seq 1, length 64
15:40:26.168127 IP 10.10.11.27 > 10.10.20.22: ICMP echo request, id 51225, seq 2, length 64
15:40:27.171187 IP 10.10.11.27 > 10.10.20.22: ICMP echo request, id 51225, seq 3, length 64

There are no replies because the default route for col0 has a higher metric (300) than eth0 (200), causing traffic to prefer eth0 over col0.

$ tcpdump -i eth0 arp or icmp
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:40:53.436768 IP 10.10.20.22 > 10.10.11.27: ICMP echo reply, id 56345, seq 0, length 64
15:40:54.440847 IP 10.10.20.22 > 10.10.11.27: ICMP echo reply, id 56345, seq 1, length 64
15:40:55.445638 IP 10.10.20.22 > 10.10.11.27: ICMP echo reply, id 56345, seq 2, length 64
15:40:56.450777 IP 10.10.20.22 > 10.10.11.27: ICMP echo reply, id 56345, seq 3, length 64

And eth0 is not able to reach subnet outside 192.168.5.0/24.

The problem here is that the default route for col0 has a higher metric (300) than eth0 (200), causing traffic to prefer eth0 over col0.
So, requests coming into col0 would not be replied from col0 by default if the remote host is not in the same subnet.

Observed behavior

Working cases (metric adjusted):

default via 10.10.20.10 dev col0 proto dhcp src 10.10.20.22 metric 100 
default via 192.168.5.2 dev eth0 proto dhcp src 192.168.5.1 metric 200 
...
192.168.5.0/24 dev eth0 proto kernel scope link src 192.168.5.1 metric 200 
  • Requests prefer col0 when the destination is outside 192.168.5.0/24.

NAT mode (shared or without --network-address)

default via 192.168.5.2 dev eth0 proto dhcp src 192.168.5.1 metric 200 
default via 192.168.106.1 dev col0 proto dhcp src 192.168.106.2 metric 300 

or

default via 192.168.5.2 dev eth0 proto dhcp src 192.168.5.1 metric 200 
  • Everything works fine because the remote host is replaced with the NAT gateway.

Solutions

  • The easiest way is to adjust the metric of col0 to be lower than eth0 (e.g. 100).

Note

This change does not affect the existing behavior for networks using only the default NAT interface (eth0).

  • Traffic within the 192.168.5.0/24 subnet will still go through eth0 as before.
  • Only the default route metric for col0 will be affected.

This change will ensure that traffic to and from the col0 interface is properly routed, allowing for seamless communication between containers and the host network.

Open to discussion if there’s a more robust approach.

@abiosoft
Copy link
Owner

abiosoft commented Sep 7, 2025

The behaviour was similar to this before i.e. the col0 interface being preferred to eth0.

However, some issues were reported (usually VPN related) when network address is enabled. Making eth0 the default route provided a consistent experience (with or without network address) and seemed to resolve the issues.

Due to that, I am leaning towards leaving the current behaviour and make it opt-in for col0 to be made the default route.

@sakkyoi
Copy link
Contributor Author

sakkyoi commented Sep 7, 2025

The previous solution I used was to add a CONNMARK to packets coming from col0, allowing return traffic to follow the original path. This is admittedly a bit more complex, but it might be another approach worth considering. More information on the implementation can be found here (not work for http, just icmp):
https://gist.github.com/sakkyoi/e2a1a33709fe8aac7009bcf23fe1570a

Another idea is to replace the NAT(eth0) with the vmnet bridge (col0) if network address is enabled. I'm not fully confident about how this might affect other components, so it could be worth discussing as a potential direction.

@sakkyoi
Copy link
Contributor Author

sakkyoi commented Sep 7, 2025

Also, I've adjusted the implementation of this PR to make the behavior opt-in by introducing a --network-preferred-route flag for now, though I'm not entirely sure if the flag name is the best fit.

@abiosoft
Copy link
Owner

abiosoft commented Sep 7, 2025

There is one more thing to do, kindly modify the embedded config file to include the corresponding section for the config.

@sakkyoi
Copy link
Contributor Author

sakkyoi commented Sep 8, 2025

Sorry, I missed that.

@abiosoft abiosoft changed the title net: fix vmnet routing net: add option to make vmnet the default route Sep 8, 2025
@abiosoft abiosoft merged commit 9866baa into abiosoft:main Sep 8, 2025
11 checks passed
@abiosoft
Copy link
Owner

abiosoft commented Sep 8, 2025

Thanks :)

@a0s
Copy link

a0s commented Sep 18, 2025

Hi! I am not sure this is the best place to ask my question, but seems relevant.
Is it possible to remove or just do not create eth0 on colima start? I want to have bridge (col0) only.

@abiosoft
Copy link
Owner

Hi! I am not sure this is the best place to ask my question, but seems relevant. Is it possible to remove or just do not create eth0 on colima start? I want to have bridge (col0) only.

@a0s it is not supported at the moment.
The provisioning of the virtual machine requires an active network interface. The external address is not guaranteed to be successful, and bridge mode is even less guaranteed.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [abiosoft/colima](https://github.com/abiosoft/colima) | minor | `v0.8.4` -> `v0.9.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>abiosoft/colima (abiosoft/colima)</summary>

### [`v0.9.1`](https://github.com/abiosoft/colima/releases/tag/v0.9.1)

[Compare Source](abiosoft/colima@v0.9.0...v0.9.1)

#### Highlights

This is a hotfix release to address disk error issues for a subset of users.

Check [v0.9.0 release notes](https://github.com/abiosoft/colima/releases/tag/v0.9.0) for the main release notes.

#### Commits

- vm: fix root disk size getting set to zero by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1418](abiosoft/colima#1418)
- k3s: customizable listen port by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1419](abiosoft/colima#1419)

**Full Changelog**: <abiosoft/colima@v0.9.0...v0.9.1>

### [`v0.9.0`](https://github.com/abiosoft/colima/releases/tag/v0.9.0)

[Compare Source](abiosoft/colima@v0.8.4...v0.9.0)

#### Highlights

This is a new release with several fixes and new features.

#### New Features

##### Bridged network

This has been a long requested feature and it is finally here.  A new `--network-mode` flag has been introduced.
Valid options are `shared` and `bridged` with the default being `shared`.

```
colima start --network-address --network-mode bridged
```

⚠️  Bridged should only be used if required and the local network is compatible. Shared networking is still the recommended option and remains the default.

##### Persistent Disk

**This applies only to newly created instances.**

Colima now uses a separate virtual machine disk for container data as a means to guard against accidental loss of data.
A deleted instance would not delete the container data disk, and a subsequent `colima start` would attempt to reinstate the data.

Supported for Docker, Containerd and Incus runtimes. Kubernetes however is not yet support.

To delete all data, the `--data` flag should be passed to `colima delete`.

```sh
colima delete --data # delete instance and container data
```

⚠️  While it works reliably, there  are no guarantees against loss of data. It should be used as a disaster recovery mechanism.

#### Fixes

- The previous behaviour with templates has been reinstated. i.e. Colima would load config from template file if present. It can still be disabled by passing `--template=false` to `colima start`.
- DNS resolution for `host.docker.internal` has been improved and now works fine in Docker, Containerd and Kubernetes containers.
- `/tmp/colima` has been removed as a default mount due to issues caused when Colima is being run by multiple users on macOS.
- Port forwarder is now configurable between `ssh` and `grpc` with the `--port-forwarder` flag. Defaults to `ssh`.
- Fix for 386 architecture emulation when Rosetta is enabled.
- Introduction of `--network-preferred-route` flag to use the network address interface as the default route when network address is enabled. This resolves networking issue for some users.
- The size of the default storage pool for Incus runtime is now synced on startup to align with the available disk space on the virtual machine.

##### Runtime version bumps

**NOTE:** container runtime versions can be updated manually by running the `colima update` command.

- Docker version updated to `v28.4.0`
- Nerdctl version updated to `v2.1.4`
- Incus version updated to `v6.16`
- K3s version defaults to `v1.33.4+k3s1 `

#### Commits

- k3s: retry ip address retrieval during setup by [@&#8203;Nevon](https://github.com/Nevon) in [#&#8203;1374](abiosoft/colima#1374)
- build(deps): bump actions/download-artifact from 4.3.0 to 5.0.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;1377](abiosoft/colima#1377)
- build(deps): bump actions/checkout from 4.2.2 to 5.0.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;1378](abiosoft/colima#1378)
- chore: replace net.ParseIP("0.0.0.0") with net.IPv4zero by [@&#8203;alexandear](https://github.com/alexandear) in [#&#8203;1375](abiosoft/colima#1375)
- chore: remove tmp mount by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1379](abiosoft/colima#1379)
- cli: default template flag to true. by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1380](abiosoft/colima#1380)
- net: use internal dnsmasq by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1381](abiosoft/colima#1381)
- net: add support for bridged mode by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1382](abiosoft/colima#1382)
- misc: improve password prompt message for network setup by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1383](abiosoft/colima#1383)
- vm: make port forwarder configurable by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1384](abiosoft/colima#1384)
- chore: fix default value for portForwarder by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1385](abiosoft/colima#1385)
- core: update disk images by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1387](abiosoft/colima#1387)
- chore: update start command k3s-args example by [@&#8203;jessegonzalez](https://github.com/jessegonzalez) in [#&#8203;1386](abiosoft/colima#1386)
- vm: enable 386 emulation regardless of rosetta by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1388](abiosoft/colima#1388)
- config: consider MountPoint in checkOverlappingMounts by [@&#8203;sakkyoi](https://github.com/sakkyoi) in [#&#8203;1391](abiosoft/colima#1391)
- net: add option to make vmnet the default route by [@&#8203;sakkyoi](https://github.com/sakkyoi) in [#&#8203;1392](abiosoft/colima#1392)
- build(deps): bump actions/setup-go from 5.5.0 to 6.0.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;1394](abiosoft/colima#1394)
- docs: add contribution instructions. by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1396](abiosoft/colima#1396)
- vm: use external disk for container runtime by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1397](abiosoft/colima#1397)
- core: update disk images by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1398](abiosoft/colima#1398)
- vm: fix service clash with runtime disk mount by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1399](abiosoft/colima#1399)
- vm: fix runtime disk mount directories for containerd by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1400](abiosoft/colima#1400)
- vm: validate container runtime for the runtime disk by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1401](abiosoft/colima#1401)
- vm: improve container runtime disk by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1404](abiosoft/colima#1404)
- docs: add how to edit colima default template file to README by [@&#8203;olamilekan000](https://github.com/olamilekan000) in [#&#8203;1405](abiosoft/colima#1405)
- Improvements to dedicated runtime disk by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1408](abiosoft/colima#1408)
- chore: code cleanups by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1409](abiosoft/colima#1409)
- incus: fix unavailable storage pool on restart by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1410](abiosoft/colima#1410)
- Pre release cleanup by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1411](abiosoft/colima#1411)
- incus: rework runtime disk by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1412](abiosoft/colima#1412)
- expose configuration for root disk size by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1413](abiosoft/colima#1413)
- Disk Cleanups by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1414](abiosoft/colima#1414)
- incus: sync size of the default pool on startup by [@&#8203;abiosoft](https://github.com/abiosoft) in [#&#8203;1415](abiosoft/colima#1415)

#### New Contributors

- [@&#8203;jessegonzalez](https://github.com/jessegonzalez) made their first contribution in [#&#8203;1386](abiosoft/colima#1386)
- [@&#8203;sakkyoi](https://github.com/sakkyoi) made their first contribution in [#&#8203;1391](abiosoft/colima#1391)

**Full Changelog**: <abiosoft/colima@v0.8.4...v0.9.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMjcuMiIsInVwZGF0ZWRJblZlciI6IjQxLjEzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants