我在 freebsd 13 上的桥接配置不正确,因为任何基于 Ubuntu 21.04 和 Windows 10 的 bhyve VM 都无法连接到互联网

我在 freebsd 13 上的桥接配置不正确,因为任何基于 Ubuntu 21.04 和 Windows 10 的 bhyve VM 都无法连接到互联网

我已经在 freebsd 13 上配置了桥接和 tap 接口,因为我想启动并使用基于 Ubuntu 21.04 和 Windows 10 的 bhyve VM,但不幸的是,经过多次阅读和帮助请求:

Reddit:https://www.reddit.com/r/Ubuntu/comments/p38ru1/ubuntu_2104_cant_connect_to_internet_when_it_is/

freebsd 论坛:

  1. https://forums.freebsd.org/threads/how-to-duplicate-the-tap0-interface-in-a-new-tap1-network-interface-that-it-is-not-used.81671/page-2#post-527355

  2. https://forums.freebsd.org/threads/ubuntu-budgie-emulated-with-bhyve-doesnt-connect-to-internet-because-the-error-network-unreachable-n-2.81340/#post-524303

  3. https://forums.freebsd.org/threads/im-tryng-to-emulate-ubuntu-budgie-with-bhyve-but-it-doesnt-connect-to-internet-because-the-error-network-unreachable.80916/#post-517845

问:https://askubuntu.com/questions/1357670/ubuntu-21-04-cant-connect-to-internet-when-it-is-emulated-with-bhyve-on-my-free

unix stackexchange:https://unix.stackexchange.com/questions/664466/ubuntu-21-04-cant-connect-to-internet-when-it-is-emulated-with-bhyve-on-my-free?noredirect=1#comment1250440_664466

我一直不明白为什么 Ubuntu 和 Windows 10 VM 无法连接到互联网,而如果我使用 vm-bhyve,它会以不同的方式配置网络,并且虚拟机可以连接到互联网。由于我不是程序员,我无法查看 vm-bhyve 代码,也无法理解密钥是什么。下面我想给你一些有用的信息,以了解我如何在 FreeBSD 和 Ubuntu 上配置桥接器和 tap 接口。

/etc/resolv.conf

search homenet.telecomitalia.it
nameserver 127.0.0.1
options edns0

my /etc/rc.conf is like this :

hostname="marietto"
keymap="it.kbd"
ifconfig_em0="DHCP"
local_unbound_enable="YES"
sshd_enable="YES"
powerd_enable="YES"
ntpdate_enable="YES"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
dumpdev="NO"
dbus_enable="YES"
slim_enable="NO"
libvirt_enable="YES"
linux_enable="YES"
linux_mounts_enable="YES"
gateway_enable="YES"
kld_list="fusefs"
lightdm_enable="NO"
sendmail_enable="NO"
microcode_update_enable="YES"
fsck_y_enable="YES"
tcp_drop_synfin="NO"
telnet_enable="NO"
cupsd_enable="NO"
portmap_enable="NO"
rlogin_enable="NO"
inetd_enable="NO"
webcamd_enable="NO"
samba_enable="NO"
lpd_enable="NO"
winbindd_enable="NO"
nfs_server_enable="NO"
nfs_client_enable="NO"
vm_enable="YES"
vm_dir="/mnt/da1p1/vms/os/"

我的 /boot/loader.conf 是这样的:

vmm_load="YES"
nmdm_load="YES"
if_tap_load="YES"
if_bridge_load="YES"
fusefs_load="YES"
linprocfs_load="YES"
linsysfs_load="YES"
tmpfs_load="YES"
verbose_loading="YES"
vboxdrv_load="YES"
console=vga,com1
boot_multicons="YES"
boot_serial="YES"
console="comconsole,vidconsole"

我的文件 /etc/sysctl.conf 是这样的:

net.link.tap.up_on_open=1
net.inet.ip.forwarding=1

我在这里阅读了一些关于该做什么的指导:https://wiki.freebsd.org/bhyve/UEFI,特别是特别是在本节中:

kldload vmm
ifconfig tap0 create up
ifconfig bridge0 create up
ifconfig bridge0 addm em0

作为第一次尝试,根据 Vasily Postnicov 的建议,我尝试以不同的方式配置 freebsd 和 linux 的网络接口,以便能够为使用 bhyve 模拟的 ubuntu 提供互联网连接。这是我所做的:

root@marietto:/home/marietto # ifconfig em0 delete


root@marietto:/home/marietto # dhclient bridge0


DHCPDISCOVER on bridge0 to 255.255.255.255 port 67 interval 4
DHCPOFFER from 192.168.1.1
DHCPREQUEST on bridge0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.2 -- renewal in 10800 seconds.


root@marietto:/home/marietto # ifconfig tap0 create up

root@marietto:/home/marietto # ifconfig bridge0 addm tap0

root@marietto:/usr/home/marietto # ifconfig


em0: flags=8963<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=4810099<RXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,VLAN_HWFILTER,NOMAP>
ether e0:d5:5e:e2:1f:22
inet 0.0.0.0 netmask 0xff000000 broadcast 255.255.255.255
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet 127.0.0.1 netmask 0xff000000
groups: lo
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>


bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 58:9c:fc:10:ff:b7
inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
member: tap0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
ifmaxaddr 0 port 5 priority 128 path cost 2000000
member: em0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
ifmaxaddr 0 port 1 priority 128 path cost 2000000
groups: bridge
nd6 options=9<PERFORMNUD,IFDISABLED>


vm-public: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether b6:74:ff:a8:4d:4e
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
groups: bridge vm-switch viid-4c918@
nd6 options=9<PERFORMNUD,IFDISABLED>



tap0: flags=8903<UP,BROADCAST,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=80000<LINKSTATE>
ether 58:9c:fc:10:ff:8e
groups: tap
media: Ethernet autoselect
status: no carrier
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

不幸的是,虚拟机启动后,freebsd 上的 em0 接口会再次获得旧的 IP 号码:192.168.1.6,并且我失去了与 FreeBSD 上的网络的连接。

作为进一步的尝试,我做了以下事情:(考虑到我正在尝试在 Freebsd 上进行并行网络配置,因为我想保留安装的 vm-bhyve。无论如何,我已经多次删除了 vm-bhyve,并尝试为 bhyve 配置桥接网络,但即使在这种情况下它也不起作用。简而言之,它只在第一次起作用,但我无法再成功重复这些步骤。只有当我让 vm-bhyve 自行配置网络时它才会起作用。这是我的 FreeBSD 上的网络/桥接配置的初始状态,安装了 vm-bhyve,但没有启动虚拟机。

marietto@marietto:~ $ ifconfig

em0: flags=8963<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=481009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,VLAN_HWFILTER,NOMAP>
ether e0:d5:5e:e2:1f:22
inet 192.168.1.6 netmask 0xffffff00 broadcast 192.168.1.255
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet 127.0.0.1 netmask 0xff000000
groups: lo
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

vm-public: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 0a:77:93:94:d5:77
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
member: em0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
       ifmaxaddr 0 port 1 priority 128 path cost 20000
groups: bridge vm-switch viid-4c918@
nd6 options=9<PERFORMNUD,IFDISABLED>

由于我已经有一个桥接接口(vm-public),因此创建另一个桥接接口(bridge0)没有任何意义,因此在终端上我执行以下操作:

root@marietto:/home/marietto # kldload vmm
kldload: can't load vmm: module already loaded or in kernel

root@marietto:/home/marietto # ifconfig tap0 create up

root@marietto:/home/marietto # ifconfig vm-public addm tap0

因此,按照上述方法配置后,FreeBSD 上的网络配置如下所示:

root@marietto:/home/marietto # ifconfig

em0: flags=8963<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=4810099<RXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,VLAN_HWFILTER,NOMAP>
ether e0:d5:5e:e2:1f:22
inet 192.168.1.6 netmask 0xffffff00 broadcast 192.168.1.255
media: Ethernet autoselect
status: no carrier
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet 127.0.0.1 netmask 0xff000000
groups: lo
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

vm-public: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 0a:77:93:94:d5:77
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
member: tap0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
       ifmaxaddr 0 port 4 priority 128 path cost 2000000
member: em0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
       ifmaxaddr 0 port 1 priority 128 path cost 20000
groups: bridge vm-switch viid-4c918@
nd6 options=9<PERFORMNUD,IFDISABLED>

tap0: flags=8903<UP,BROADCAST,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=80000<LINKSTATE>
ether 58:9c:fc:10:ff:8e
groups: tap
media: Ethernet autoselect
status: no carrier
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

然后,我使用以下命令启动 bhyve VM:

bhyve -c 4 -m 8G -w -H \
-s 0,hostbridge \
-s 4,virtio-blk,/mnt/da1p1/vms/os/ubuntu-budgie-gpu/ubuntu-2104-gpu.img \
-s 5,virtio-net,tap0 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=1440,h=900,wait \
-s 30,xhci,tablet \
-s 31,lpc -l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
-s 20,hda,play=/dev/dsp8,rec=/dev/dsp8 \
vm0

正如我所说,Ubuntu VM 无法连接到互联网。下面我想向您展示我如何配置 Ubuntu。在 Ubuntu 上,我的 /etc/resolv.conf 文件如下:

nameserver 127.0.0.53
options edns0 trust-ad
search homenet.telecomitalia.it

另外,我在文件夹 /etc/netplan 中创建了一个 netplan 文件,其中包含以下内容:

network
    version: 2
    renderer: NetworkManager
    ethernets:
       enp0s5:
           addresses:
                - 192.168.1.7/24
           gateway4: 192.168.1.1
           nameservers:
                     search : [homenet.telecomitalia.it]
                     addresses: 192.168.1.1

netplan apply,结果如下:

网络接口 enp0s5 获取 IP 号 192.168.1.7 ping 192.168.1.7 : OK ping 192.168.1.6 (FreeBSD IP) = 目标主机不可达 ping 192.168.1.1 : 目标主机不可达 PING google.it (172.217.21.67) : 主机不可达

tcpdump:

listening on enp0s5,link-type EN10MB (Ethernet),capture size 262144 bytes

20:58:04:688913 ARP, request who-has 192.168.1.1 tell 192.168.1.7,length 28

路线-n

destination     gateway        genmask              flags metric ref  use  iface

0.0.0.0            192.168.1.1   0.0.0.0                UG     100     0    0     enp0s5
169.254.0.0    0.0.0.0           255.255.0.0        U       1000    0    0    enp0s5
192.168.1.0    0.0.0.0           255.255.255.0    U       100      0    0    enp0s5

IP 路由列表

default via 192.168.1.1 dev enp0s5 proto static metric 100
169.254.0.0/16 dev enp0s5 scope link metric 100
192.168.1.0/24 dev enp0s5 proto kernel scope link src 192.168.1.7 metric 100

ping google.it = 名称解析暂时错误

ubuntu 上的防火墙 = 未安装 路由器上的防火墙 = 关闭

相反,从 freebsd 到 ubuntu:

ping 192.168.1.7 :主机已关闭

网络之星-r

routing tables

internet:

destination         gateway        flags     Netif Expire

default                modemtim    UGS      em0
localhost             link#2           UH        lo0
192.168.1.0/24   link#1           U          em0
192.168.1.6        link#1           UHS      lo0

我忘了。如果我删除 netplan conf 文件并让 ubuntu 通过 DHCP 选择 IP,就会发生这种情况:

/etc/netplan.conf

network:
    version: 2
    renderer: networkd
    ethernets:
        enp3s0:
            dhcp4: true

ping PING google.it (172.217.21.67) : 网络无法访问。还有什么?

附言:由于我不是真正的系统管理员,而只是把它当作一种爱好,所以不要给我泛泛的建议,因为我可能不明白该怎么做。如果你想成为一个善良的人,请尽量做到详尽和精确。你会帮助我了解如何解决问题。谢谢。

相关内容