Solved BHYVE Linux VM Can Ping Host but No Internet

Hi there.

I've created a Alpline VM using Bhyve. I'm using WLAN0 so I am using NAT. My problem is the host and VM can ping each other but the VM can't see the Internet.
I've setup the network with:

Code:
ifconfig bridge create name natif up
ifconfig tap0 create up
ifconfig natif addm tap0
ifconfig natif inet 10.0.0.1/24
ifconfig tap0 up

pf.conf:

Code:
ext_if="wlan0"
virt_net="10.0.0.0/24"
scrub all
nat on $ext_if from $virt_net to any -> ($ext_if)
pass log all

I've made sure PF is running and there are no syntax errors and IP forwarding is allowed:

Code:
service pf restart
sysctl net.inet.ip.forwarding=1

I run the VM using:

Code:
bhyve -c 1 -m 2G -w -H\
      -s 0,hostbridge\
      -s 3,ahci-cd,alpine-standard-3.20.2-x86_64.iso\
      -s 4,virtio-blk,/dev/zvol/zroot/linuxvm\
      -s 5,virtio-net,tap0\
      -s 29,fbuf,tcp=0.0.0.0:5900,w=800,h=600,wait\
      -s 30,xhci,tablet\
      -s 31,lpc -l com1,stdio\
      -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd\
      linuxvm

I assign a static IP to my VM using:

Code:
ifconfig eth0 10.0.0.2

The VM can ping 10.0.0.1 and my host can also ping 10.0.0.2

But there is no Internet connectivity from the VM.

Does anyone have any suggestions?

Thank you.
 
Turn on routing on the host; sysrc gateway_enable="YES"

sysctl net.inet.ip.forwarding=1
While this will enable routing, the value isn't stored, so it'll be gone after a reboot.

I assign a static IP to my VM using:
You need a subnet mask and also set a gateway. Without a gateway it won't know how to route traffic outside the subnet. If you don't supply a subnet mask it's going to assume 10.0.0.2 is a class A network and set the mask to 255.0.0.0 (10.0.0.0/8).
 
Back
Top