Enabling Networking between KVM host and guests.

In this post, I describe how to realise L2 reachability between KVM host and guest on Arch Linux.
There are several interface mode on KVM guests. Here, I will use MacVTap (bridge mode).

0. Method 1, using ip command.


# Creating an macvlan interface binds to enp0s25.
sudo ip link add link enp0s25 macvlan0 type macvlan mode bridge

# Set an IP address.
# Make sure to use different IP address from physical interface's.
# or, just delete an IP address from physical interface.
sudo ip addr add 192.168.0.10/24 dev macvlan0

# Erasing all routing tables.
sudo ip route flush dev enp0s25
sudo ip route flush dev macvlan0

# Adding routes
sudo ip route add 192.168.0.0/24 dev macvlan0 src 192.168.0.10 metric 0
sudo ip route add default via 192.168.0.1 dev macvlan0

2. Using netctl to make it permanent.


vim /etc/netctl/macvlan0

Description='macvlan0 for kvm'
Interface=macvlan0
Connection=macvlan
# The variable name is plural, but needs precisely one interface
BindsToInterfaces=enp0s25
# MACVLAN Mode
Mode="bridge"
# Optional static MAC Address for MACVLAN interface
MACAddress="26:39:c8:6f:c6:37"
IP=dhcp

netctl disable enp0s25
netctl enable macvlan0

That’s all

Advertisements