1. Segments, leases, and static IPs
Declare isolated networks and control who gets which address.
After this lesson you can
- Declare segments with subnet - Attach VMs with nic { segment = … } for DHCP leases - Reserve a static address with nic { ip = … }
A segment is an isolated L2 network with a built-in DHCP and DNS server, entirely in userspace. VMs join it with nic { segment = "corp" } and get a lease; add ip = "10.50.0.10" to the nic and the address becomes a DHCP reservation — the guest still just does DHCP, but always receives that address. Guests on one segment see each other and nothing else.
VM names resolve over the segment's DNS, so guests reach each other by name (ping web01) without caring who leased what.
§ 1Exercise: Two guests, one wire
Declare two Alpine VMs on one segment — one static, one dynamic — and ping between them.
segment "corp" { subnet = "10.50.0.0/24" nat = true }
vm "a" {
template = "ghcr.io/vmlabdev/vmlab-templates/alpine-3.23"
memory = 1GiB
nic { segment = "corp" ip = "10.50.0.10" }
}
vm "b" {
template = "ghcr.io/vmlabdev/vmlab-templates/alpine-3.23"
memory = 1GiB
nic { segment = "corp" }
}
Expected result
vmlab exec b -- ping -c1 10.50.0.10 (or ping -c1 a) succeeds; vmlab status shows a holding exactly 10.50.0.10.
Hint
The reserved ip must sit inside the segment's subnet — vmlab validate rejects an out-of-range reservation.