-1

TLDR?

“在大多数配置中,macvtap 不适用于主机到访客网络通信”

我在带有单个以太网的 intel nuc 上设置了 virt-manager。

我还将它设置在具有 x4 以太网的超微服务器上,该服务器是桥接的(nm-bridge),其中使用 veth 来托管我的 VM 可以看到主机的 macvtap 设备。

我读到我需要在这里设置一个桥(我做了,将我的单个 eno1 分配给 nm-bridge)

https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/kvm-guests-and-host-cannot-see-each-other-4175466210/

但它没有提到如何设置正确的 veth 设备。

我在这里找到了如何做到这一点的指南

https://developers.redhat.com/blog/2018/10/22/introduction-to-linux-interfaces-for-virtual-networking/

但给出的示例使用命名空间(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

基本上我试图让我的虚拟机与我的主机交谈

4

1 回答 1

0

Found a solution

https://www.furorteutonicus.eu/2013/08/04/enabling-host-guest-networking-with-kvm-macvlan-and-macvtap/

#!/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
于 2021-04-05T15:31:18.977 回答