1ee537d9bSRob Bradford# Using MACVTAP to Bridge onto Host Network 2ee537d9bSRob Bradford 38160c288SDayu LiuCloud Hypervisor supports using a MACVTAP device which is derived from a MACVLAN. Full details of configuring MACVLAN or MACVTAP is out of scope of this document. However the example below indicates how to bridge the guest directly onto the network the host is on. Due to the lack of hairpin mode it not usually possible to reach the guest directly from the host. 4ee537d9bSRob Bradford 5ee537d9bSRob Bradford```bash 6ee537d9bSRob Bradford# The MAC address must be attached to the macvtap and be used inside the guest 7ee537d9bSRob Bradfordmac="c2:67:4f:53:29:cb" 8ee537d9bSRob Bradford# Host network adapter to bridge the guest onto 9ee537d9bSRob Bradfordhost_net="eno1" 10ee537d9bSRob Bradford 11ee537d9bSRob Bradford# Create the macvtap0 as a new virtual MAC associated with the host network 12ee537d9bSRob Bradfordsudo ip link add link "$host_net" name macvtap0 type macvtap 13ee537d9bSRob Bradfordsudo ip link set macvtap0 address "$mac" up 14ee537d9bSRob Bradfordsudo ip link show macvtap0 15ee537d9bSRob Bradford 16ee537d9bSRob Bradford# A new character device is created for this interface 17ee537d9bSRob Bradfordtapindex=$(< /sys/class/net/macvtap0/ifindex) 18ee537d9bSRob Bradfordtapdevice="/dev/tap$tapindex" 19ee537d9bSRob Bradford 20ee537d9bSRob Bradford# Ensure that we can access this device 21*da5fae38SWei Liusudo chown "$UID:$UID" "$tapdevice" 22ee537d9bSRob Bradford 23ee537d9bSRob Bradford# Use --net fd=3 to point to fd 3 which the shell has opened to point to the /dev/tapN device 24ee537d9bSRob Bradfordtarget/debug/cloud-hypervisor \ 25ee537d9bSRob Bradford --kernel ~/src/linux/vmlinux \ 26ee537d9bSRob Bradford --disk path=~/workloads/focal.raw \ 27ee537d9bSRob Bradford --cpus boot=1 --memory size=512M \ 28ee537d9bSRob Bradford --cmdline "root=/dev/vda1 console=hvc0" \ 29ee537d9bSRob Bradford --net fd=3,mac=$mac 3<>$"$tapdevice" 30ee537d9bSRob Bradford``` 31ee537d9bSRob Bradford 32ee537d9bSRob BradfordAs the guest is now connected to the same L2 network as the host you can obtain an IP address based on your host network (potentially including via DHCP) 33