Networking
A lab wires its nodes together with two kinds of network: switches and links. A switch is a shared network that the Mac is part of, with optional NAT, DHCP and DNS. A link is a cable between exactly two NICs, with nothing else on it. This page shows when to use which and how to change the wiring while a lab runs.
| Switch | Link | |
|---|---|---|
| Backed by | a vmnet network | a socketpair |
| Members | any number of NICs, plus the Mac | exactly two NICs, on two different nodes |
| The Mac takes part | yes, it has the first address | no, frames go straight from VM to VM |
| DHCP, DNS, NAT | built in, each can be turned off | none: configure addresses in the guest |
| Port forwarding | yes, on NAT switches | no |
| Limits | vmnet documents 4 per VM and 32 in total (warnings) | none |
| Good for | management access, internet, services the Mac uses | routing labs, point-to-point cables, VLAN trunks, bonding |
Interfaces
Each node lists its NICs under interfaces. The list order is the PCI order in the guest.
interfaces:
- { name: mgmt, attach: switch/mgmt, mac: "52:54:00:12:01:00" }
- { name: p2p, attach: link/a-b }
- { name: spare } # a free NIC: not plugged into anything| Key | Meaning |
|---|---|
name | Label used by vz (vz port down a/p2p). Not pushed into the guest. Letters, digits, ., _, -, up to 15 characters, starting with a letter. |
attach | switch/<name> or link/<name>. Leave it out for a free NIC. |
mac | Optional fixed MAC. |
connected | false starts with the cable unplugged. Default true. Not allowed on a free NIC. |
Stable MAC addresses
Without mac, vz derives a MAC from the lab, node and interface names: a locally administered address that starts with 02:. The same names give the same MAC on every Mac, so leases and guest config survive restarts. Renaming the lab, node or interface changes it.
Set mac yourself when cloud-init or a DHCP reservation needs to know it. A MAC must be unicast (even first byte) and unique in the lab. The examples use 52:54:00:NN:<node>:<nic>.
Switches
switches:
mgmt:
nat4: true
ipv4Subnet: 10.101.0.0/24
dhcpReservations:
- { mac: "52:54:00:01:01:00", ipv4: 10.101.0.11 }| Key | Default | Meaning |
|---|---|---|
nat4 | false | IPv4 NAT to the internet |
nat6 | false | IPv6 NAT to the internet |
ipv4Subnet | chosen by vmnet | Subnet in CIDR form, /30 or larger. The Mac gets the first address. |
ipv6Prefix | chosen by vmnet | IPv6 prefix, for example fd00:120::/64 |
mtu | 1500 | 1280 to 65535 |
dhcp | true | Built-in DHCP server |
dhcpReservations | [] | Optional fixed IPv4 addresses by MAC |
dnsProxy | true | Built-in DNS proxy on the Mac's address |
routerAdvertisement | true | IPv6 router advertisements |
portForwarding | [] | Mac ports forwarded to guests, NAT switches only |
Shared or host-only
The NAT keys decide the vmnet mode:
nat4ornat6istrue: shared mode. The VMs reach the internet through the Mac.- both are
false: host mode. The VMs reach each other and the Mac, nothing else. Use it for anything that must stay offline (example 03).
In shared mode, the family you leave false gets no NAT: nat6: true alone gives IPv6 NAT without IPv4 NAT.
Subnets
- The Mac always has the first host address (
10.101.0.1in10.101.0.0/24). Point guests at it as their gateway and DNS server. - Subnets of switches in the same lab must not overlap. Labs running at the same time must not overlap either: vz only checks one lab file, and vmnet can then fail to create the second lab's switch (
VMNET_FAILUREorVMNET_SHARING_SERVICE_BUSY). - Writing host bits (
10.101.0.5/24) is a warning; the network address is used. - Without
ipv4Subnet, vmnet picks one. That is fine for a quick test, but fixed subnets make addresses predictable.
DHCP reservations
Reservations are optional. Without them, every NIC on a switch with dhcp: true still gets an address: the next free one in the switch's DHCP pool. You only learn it after the guest has booted, from vz node ls (source lease or hostname, see Find a node's address).
Reserve an address when you want to know it before vz up: to SSH to a fixed address, for a port forward, an Ansible inventory or a route in another node. That is why the examples reserve one for every switch NIC.
nodes:
- name: web
interfaces:
- { name: mgmt, attach: switch/mgmt, mac: "52:54:00:05:01:00" }
switches:
mgmt:
nat4: true
ipv4Subnet: 10.105.0.0/24
dhcpReservations:
- { mac: "52:54:00:05:01:00", ipv4: 10.105.0.11 }vz checks every reservation:
- an interface on that switch must have the same
mac(set it on the interface), - each MAC and each address is reserved once,
- the address is inside
ipv4Subnet, and is not the network, broadcast or the Mac's address, dhcpmust betrue.
The guest must identify itself by its MAC for the reservation to apply. See cloud-init.
No DHCP or no DNS
Example 04 turns DHCP off and configures every address in cloud-init. Example 23 has one switch per feature: dhcp: false, dnsProxy: false, routerAdvertisement: false, IPv6 and mtu: 9000.
Port forwarding
Publish a guest port on the Mac. Only NAT switches can forward.
switches:
mgmt:
nat4: true
ipv4Subnet: 10.105.0.0/24
portForwarding:
- { protocol: tcp, hostPort: 8080, address: 10.105.0.11, guestPort: 80 }
- { protocol: tcp, hostPort: 2222, address: 10.105.0.11, guestPort: 22 }
dhcpReservations:
- { mac: "52:54:00:05:01:00", ipv4: 10.105.0.11 }curl http://localhost:8080
ssh -p 2222 lab@localhost| Key | Meaning |
|---|---|
protocol | tcp or udp |
family | ipv4 or ipv6. Optional: inferred from address. IPv4 needs nat4: true, IPv6 needs nat6: true. |
hostPort | Port on the Mac, 1 to 65535. Each protocol, family and port can be forwarded once across the lab. |
address | Guest address. Reserve it with DHCP so the right node has it (otherwise a warning). |
guestPort | Port in the guest |
vmnet's forwarding does not answer on the loopback interface. For each TCP rule, vz also listens on 127.0.0.1 and ::1 and passes connections to the guest, so localhost works. If that local port is already taken, vz logs it in the lab log and leaves the port to vmnet. UDP rules are handled by vmnet only, so use the Mac's network address rather than localhost for UDP.
Links
nodes:
- name: a
interfaces:
- { name: p2p, attach: link/a-b, mac: "52:54:00:12:01:01" }
- name: b
interfaces:
- { name: p2p, attach: link/a-b, mac: "52:54:00:12:02:01" }
links:
a-b: {}A link is a virtual cable. Every frame one end sends arrives unchanged at the other end, and no vz code runs in the data path. The rules:
- exactly two interfaces attach to it, on two different nodes (use a switch for more),
- there is no DHCP and no Mac on it: set addresses in each guest's
network-config, or run your own DHCP server in a node, - an unused link is a warning.
| Key | Default | Meaning |
|---|---|---|
mtu | 1500 | MTU on both ends, 1280 to 65535 |
buffer | 4MiB | Advanced: socket send buffer (the receive buffer is twice that). 1MiB to 256MiB is expected. |
Example 17 puts a mtu: 9000 link next to a standard one. Routing labs such as 13, 14 and 30 are built almost only from links.
Find a node's address
vz node ls # alias: vz node statusFor each NIC on a switch, vz reports the address the guest is using, from the most to the least reliable source:
| Source | Meaning |
|---|---|
reservation | macOS's DHCP server holds the NIC's reservation (/etc/bootptab), so this is the address the guest gets. The guest may still be booting. |
lease | a DHCP lease in /var/db/dhcpd_leases whose client ID is this MAC |
hostname | the newest lease in the switch subnet with the node's name as hostname (guests that send a DUID). Only used when the switch has a known subnet. |
reserved | the reservation from the lab file, which macOS's DHCP server no longer holds, and no lease was found |
A lease for the same MAC can stay in the lease file after the guest moved to its reservation, so a held reservation wins over a lease.
Notes that can follow the table:
... does not hold its reservationor... is using <ip> from the DHCP pool: the reservation is gone from/etc/bootptab, usually after a node restart while another NAT lab runs.vz downandvz uprestore it. See Troubleshooting.... is using <ip>, not its reservation <ip>: the guest's DHCP client id is not its MAC: adddhcp-identifier: macto the guest's network config.
NICs on links have no address in this table: vz cannot see inside a cable. Use the console. vz node ls --json includes ip and ipSource for scripts.
Change the wiring at runtime
Unplug and plug cables on a running lab, the way you would pull a cable from a real switch:
vz link down a-b # unplug both ends of a link
vz link up a-b
vz port down vm2/mgmt # unplug one NIC (switch or link)
vz port up vm2/mgmtThe guest sees the carrier go down and up. Routing labs use this to watch protocols converge (OSPF failover, bonding).
To start with a cable unplugged, set connected: false on the interface:
interfaces:
- { name: spare, attach: switch/mgmt, mac: "52:54:00:22:01:01", connected: false }vz port up tiny/spareWhen the two ends of a link disagree about connected, vz validate warns.
NOTE
link and port change the running lab only. They are not written to the lab file, so the next vz up starts from connected as the file says.
See the topology
vz topologytopology reads the lab file only, so it works before vz up. It prints three tables:
- Switches: name, mode (
sharedorhost), MTU, IPv4 subnet, and IPv6 prefix when any switch has one, - Links: name, MTU and both ends,
- Ports: every NIC with what it is attached to (
switch/<name>,link/<name>orfree) and its MAC.
See also
- cloud-init: guest network config
- Concepts
- Lab file reference
- Validation rules
- Examples