端口转发
Lima 支持从客户机到主机的 localhost 端口自动转发。
端口转发类型
Lima 支持两种端口转发器:SSH 和 GRPC。
默认端口转发器如下表所示。
| 版本 | 默认值 |
|---|---|
| v0.1.0 | SSH |
| v1.0.0 | GRPC |
| v1.0.1 | SSH |
| v1.1.0 | GRPC |
默认设置在 Lima v1.0 中曾经改为 GRPC,但由于稳定性原因在 v1.0.1 中回退到 SSH。 在 Lima v1.1 中默认设置再次改回 GRPC,因为稳定性问题已得到解决。
使用 SSH
SSH based port forwarding was previously the default mode.
要显式使用 SSH 转发,请使用以下命令
LIMA_SSH_PORT_FORWARDER=true limactl start
Advantages
- Outperforms GRPC when VSOCK is available
Caveats
- 不支持基于 UDP 的端口转发
- 在主机上生成子进程来运行 SSH 主服务器。
SSH over AF_VSOCK
| ⚡ Requirement | Lima >= 2.0 |
|---|
If VM is VZ based and systemd is v256 or later (e.g. Ubuntu 24.10+), Lima uses AF_VSOCK for communication between host and guest. SSH based port forwarding is much faster when using AF_VSOCK compared to traditional virtual network based port forwarding.
To disable this feature, set LIMA_SSH_OVER_VSOCK to false:
export LIMA_SSH_OVER_VSOCK=false
Using GRPC
| ⚡ 要求 | Lima >= 1.0 |
|---|
在此模型中,lima 使用现有的 GRPC 通信(主机 <-> 客户机)来隧道传输端口转发请求。 对于每个端口转发请求,会创建一个 GRPC 隧道并用于传输数据
要启用此功能,请将 LIMA_SSH_PORT_FORWARDER 设置为 false:
LIMA_SSH_PORT_FORWARDER=false limactl start
优势
- Supports both TCP and UDP based port forwarding
- Performs faster compared to SSH based forwarding, when VSOCK is not available
- No additional child process for port forwarding
Accessing ports by IP address
To access a guest’s ports by its IP address, connect the guest to the vzNAT or the lima:shared network.
The vzNAT network is extremely faster and easier to use, however, vzNAT is only available for VZ guests.
limactl start --network vzNAT
lima ip addr show lima0
See Config » Network » VMNet networks for the further information.
Benchmarks
| By localhost | SSH (w/o VSOCK) | GRPC | SSH (w/ VSOCK) |
|---|---|---|---|
| TCP | 4.06 Gbits/sec | 5.37 Gbits/sec | 6.32 Gbits/sec |
| TCP Reverse | 3.84 Gbits/sec | 7.11 Gbits/sec | 7.47 Gbits/sec |
| By IP address | lima:shared | vzNAT |
|---|---|---|
| TCP | 3.46 Gbits/sec | 59.2 Gbits/sec |
| TCP Reverse | 2.35 Gbits/sec | 130 Gbits/sec |
上述基准测试详情是使用以下命令获得的
Host -> limactl start vz
VZ Guest -> iperf3 -s
Host -> iperf3 -c 127.0.0.1 //Benchmark for TCP (average of "sender" and "receiver")
Host -> iperf3 -c 127.0.0.1 -R //Benchmark for TCP Reverse (same as above)
The benchmark result, especially the throughput of vzNAT, highly depends on the performance of the hardware.
Benchmarking environment
- Lima version: 2.0.0-alpha.2
- Guest: Ubuntu 25.04
- OpenSSH 9.9p1
- iperf 3.18
- Host: macOS 26.0.1
- OpenSSH 10.0p2
- iperf 3.19.1 (Homebrew)
- Hardware: MacBook Pro 2024 (M4 Max, 128 GiB)