Virtual interface (veth) not working in libvirtd/virt-manager for bridge

1.2k Views Asked by At

TLDR?

"in most configurations, macvtap does not work for host to guest network communication"

I have virt-manager setup on an intel nuc with a single ethernet.

I also have it setup on a supermicro server with x4 ethernet that are bridged (nm-bridge) where a veth is used from this to host a macvtap device where my VM's can see the host.

I read I needed to setup a bridge here (which I did, assigning my single eno1 to nm-bridge)

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

but it doesn't mention how to setup the proper veth devices.

I found a guide here on how to do that

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

but the example given uses namespaces (netns). However on another host (that is using bridging + virtual ethernet interfaces from that bridge) I have no netns (i.e. ip netns list), nor do any of my vnet's (tun devices) or veth devices have ip's set.

I tried (gleaning from this: 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

Basically I'm trying to get my VM to talk to my host

1

There are 1 best solutions below

0
On

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