You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `dhcp-script` option tells dnsmasq to call the notification script on every lease event. The script sends the MAC and IP to VMM's `ReportDhcpLease` RPC, which triggers automatic port forwarding for the VM.
113
+
100
114
```bash
101
115
sudo systemctl restart dnsmasq
102
116
```
103
117
104
-
**4. Update vmm.toml:**
118
+
**4. Firewall rules (nftables):**
119
+
120
+
When the host firewall has a restrictive INPUT policy (e.g. `drop`), the bridge's DHCP and DNS traffic will be silently blocked. libvirt handles this automatically for virbr0, but a standalone bridge needs explicit rules.
sudo nft add rule ip nat POSTROUTING ip saddr "$SUBNET" ip daddr 224.0.0.0/24 counter return
140
+
sudo nft add rule ip nat POSTROUTING ip saddr "$SUBNET" ip daddr 255.255.255.255 counter return
141
+
sudo nft add rule ip nat POSTROUTING ip saddr "$SUBNET" ip daddr != "$SUBNET" counter masquerade
142
+
```
143
+
144
+
If the host uses libvirt, nftables rules may be in custom chains (`LIBVIRT_INP`, `LIBVIRT_FWO`, etc.) instead of the default `INPUT`/`FORWARD` chains. Adjust the chain names accordingly.
145
+
146
+
To make these rules persistent across reboots, save them with `nft list ruleset > /etc/nftables.conf` or add them to a systemd service.
- VMM passes `-netdev bridge,id=net0,br=<bridge>` to QEMU
129
173
- QEMU's bridge helper (setuid) creates a TAP device and attaches it to the bridge
130
-
- Guest MAC address is derived from SHA256 of the VM ID (stable across restarts for DHCP IP consistency)
174
+
- Guest MAC address is derived from SHA256 of the VM ID, with an optional configurable prefix (stable across restarts for DHCP IP consistency)
175
+
- The host DHCP server (dnsmasq) assigns an IP and calls `dhcp-notify.sh`, which notifies VMM via the `ReportDhcpLease` RPC
176
+
- VMM matches the MAC address to identify the VM and establishes port forwarding rules
131
177
- When QEMU exits, the TAP device is automatically destroyed
132
178
- VMM does not need root or `CAP_NET_ADMIN`
133
179
180
+
### MAC address prefix
181
+
182
+
You can configure a fixed MAC address prefix (0–3 bytes) in vmm.toml:
183
+
184
+
```toml
185
+
[cvm.networking]
186
+
mode = "bridge"
187
+
bridge = "dstack-br0"
188
+
mac_prefix = "52:54:00"
189
+
```
190
+
191
+
The remaining bytes are derived from the VM ID hash. The prefix applies to all networking modes, not just bridge. The locally-administered bit is always set on the first byte.
192
+
134
193
## Operational notes
135
194
136
195
### Do not restart the bridge while VMs are running
- libvirt injects nftables rules for NAT masquerade and forwarding automatically
143
-
-If using a manual bridge, ensure your firewall allows forwarding for the bridge subnet and has masquerade rules for outbound NAT
201
+
- libvirt automatically injects nftables rules for INPUT (DHCP/DNS), FORWARD, and NAT masquerade into its own chains (`LIBVIRT_INP`, `LIBVIRT_FWO`, `LIBVIRT_FWI`, `LIBVIRT_PRT`)
202
+
-A standalone bridge requires **all** of these rules to be added manually (see Option B step 4 above). The most common failure mode is a restrictive INPUT policy silently dropping DHCP requests from VMs — if VMs on a custom bridge don't get an IP, check `sudo nft list chain ip filter INPUT` first
144
203
- Docker's nftables chains (`DOCKER-FORWARD`) run before libvirt's but do not block virbr0 traffic
204
+
- Use `setup-bridge.sh check --bridge <name>` to diagnose missing rules
0 commit comments