如何解决虚拟接口veth在桥接的 libvirtd/virt-manager 中不起作用
TLDR?
“在大多数配置中,macvtap 不适用于主机到访客网络通信”
我在具有单个以太网的英特尔 nuc 上设置了 virt-manager。
我还在一个带有 x4 以太网的 supermicro 服务器上进行了设置,该服务器通过桥接(nm-bridge),其中使用了一个 veth 来托管一个 macvtap 设备,我的虚拟机可以在其中看到主机。
我读到我需要在这里设置一个网桥(我做到了,将我的单个 eno1 分配给 nm-bridge)
但它没有提到如何设置合适的 veth 设备。
我在这里找到了关于如何做到这一点的指南
但给出的示例使用命名空间(netns)。但是,在另一台主机上(使用桥接器的桥接 + 虚拟以太网接口),我没有 netns(即 ip netns 列表),我的任何 vnet(tun 设备)或 veth 设备也没有设置 ip。
我尝试过(从中收集:https://superuser.com/questions/764986/howto-setup-a-veth-virtual-network)
ip link add dev veth1 type veth
ip link set veth1 master nm-bridge
ip link set veth0 master nm-bridge
ip link set dev veth0 up
ip link set dev veth1 up
基本上我试图让我的虚拟机与我的主机交谈
解决方法
找到解决办法
#!/bin/sh
# Let host and guests talk to each other over macvlan.
# Configures a macvlan interface on the hypervisor.
# Run this on the hypervisor (e.g. in /etc/rc.local)
# Made for IPv4; need modification for IPv6.
# Meant for a simple network setup with only eth0,# and a static (manual) ip config.
# Evert Mouw,2013. Slightly modified in 2020.
HWLINK=enp5s0
MACVLN=macvlan0
TESTHOST=www.google.com
# ------------
# test if interface already exists
# ------------
if ip link show | grep "$MACVLN@$HWLINK" > /dev/null
then
echo "Link $MACVLN already exists on $HWLINK."
exit
fi
# ------------
# wait for network availability
# ------------
while ! ping -q -c 1 $TESTHOST > /dev/null
do
echo "$0: Cannot ping $TESTHOST,waiting another 5 seconds."
sleep 5
done
# ------------
# get network config
# ------------
IP=$(ip address show dev $HWLINK | grep "inet " | awk '{print $2}')
NETWORK=$(ip -o route | grep $HWLINK | grep -v default | awk '{print $1}')
GATEWAY=$(ip -o route | grep default | awk '{print $3}')
# ------------
# setting up $MACVLN interface
# ------------
ip link add $MACVLN link $HWLINK type macvlan mode bridge
ip address add $IP dev $MACVLN
ip link set dev $MACVLN up
# ------------
# routing table
# ------------
# empty routes
ip route flush dev $HWLINK
ip route flush dev $MACVLN
# add routes
ip route add $NETWORK dev $MACVLN metric 0
# add the default gateway
ip route add default via $GATEWAY
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。