I'm trying to wrap my head around how virtual bridges/switches/tap interfaces work under bhyve. I guess I'm doing something fundamentally stupid here (or my understanding of how this works is fundamentally wrong), but please bear with me...
I do use bhyve on a few of my machines, but on those I use wired connections like USB or Ethernet for internet access. Now on this machine, a laptop, I connect to the internet through a mifi router (NETGEAR Nighthawk M5, if it matters), so bridging doesn't work in this case, and I have to use NAT.
Before I describe my setup, I have a couple of general questions that have been bothering me:
These are the steps I followed to create/configure my guest:
The tap and wlan0 interfaces are attached to the virtual switch:
I do use bhyve on a few of my machines, but on those I use wired connections like USB or Ethernet for internet access. Now on this machine, a laptop, I connect to the internet through a mifi router (NETGEAR Nighthawk M5, if it matters), so bridging doesn't work in this case, and I have to use NAT.
Before I describe my setup, I have a couple of general questions that have been bothering me:
- I see lots of documentation about assigning a bridge or virtual switch an IP address. How is that possible? My understanding is that switches, for example, simply "route" (not in the layer 3 sense) frames to the correct ports on the switch. Same things with bridges: it's a device that bridges two different networks, and doesn't have a NIC for it to be assigned an IP address.
- A tap interface, which is a virtual NIC (correct me if I'm wrong), can be assigned an IP address, and is usually "attached" to a guest machine. The problem is it is also available for configuration on the host with something like ifconfig, so how does that work? Do I configure it from the host? The guest? What happens if I say "ifconfig tap0 192.168.1.5" on the host and give it a different address in the guest?
These are the steps I followed to create/configure my guest:
vm switch create public
andvm switch add public wlan0
.- Use virtio-net in my vm-bhyve config (
network0_type="virtio-net"
andnetwork0_switch="public"
) and install the virtio driver under Windows. sysctl net.inet.ip.forwarding=1
- Add
nat on wlan0 from 10.5.10.0/8} to any -> (wlan0)
to pf.conf and enable pf (I don't do it in rc.conf, but I do runservice pf onestart
).
- Guest IP 10.5.10.2/8, default gateway 10.5.5.1 or 10.5.10.1 (tried both).
- Assign vm-public an IP of 10.5.10.1.
The tap and wlan0 interfaces are attached to the virtual switch:
Code:
t14s# vm switch info public
local: _netgraph,: bad variable name
------------------------
Virtual Switch: public
------------------------
type: standard
ident: vm-public
vlan: -
physical-ports: wlan0
bytes-in: 47056 (45.953K)
bytes-out: 3487760 (3.326M)
virtual-port
device: tap0
vm: windows11