KVM Virtual Networking Concepts
External
Internal
Overview
This article discusses concepts related to virtual networking with libvirt.
Virtual Network Switch
libvirt implements virtual networking using a virtual network switch. A virtual network switch is a software component that runs on the virtualization host. The virtual machine guests connect to it and the network traffic to and from the guests passes through the virtual switch, forming a virtual network. From a guest's operating system point of view, a virtual network connection is the same as a normal physical network connection.
The virtual switch is started and managed by the libvirtd daemon and is represented as the virbr0 network interface:
# ip addr ... 7: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000 link/ether 52:54:00:15:ef:87 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever ...
The virtual network switch can operate in several modes, described below:
The virtual network can be restricted to a specific physical network interface. This may be useful on virtualization hosts that have several physical interfaces, and it only matters for NAT and routed modes. This behavior can be defined when the virtual network is created, by specifying "dev=<interface>".
The DNS and DHCP Server
The virtual network switch uses a DNS and DHCP server. The DNS and DHCP are both served by a dnsmasq instance running on the virtualization host. Each virtual switch instance has its own dnsmasq instance. The configuration file is /var/lib/libvirt/dnsmasq/default.conf, but the configuration file should not be edited manually, but with
virsh net-edit default
The Default Networking Configuration
By default, all guests on a virtualization host are connected to a virtual network switch running in NAT mode, in the same virtual network named "default".
Virtual Network Modes
NAT Mode
The NAT mode is the default mode in which libvirt virtual network switch operates, without additional configuration.
All guests have direct connectivity to each other and to the virtualization host. libvirt network filtering and guest operating system iptables rules apply. The guests can access external networks by network address translation, subject to the host system's firewall rules. The network address translation function is implemented as IP masquerading, using iptables rules. Connected guests will use the virtualization host physical machine IP address for communication with external networks (it is possible that the virtualization host IP address is unroutable as well, if the virtualization host sits in its own NAT domain). By default, without additional configuration, external hosts cannot initiate connections to the guest virtual machines.
Routed Mode
The libvirt virtual network switch can be configured to run in routed mode. In routed mode, the switch connects to the physical LAN the virtualization host is attached to, without the intermediation of a NAT module. All the guest virtual machines are in the same subnet, routed through the virtual switch. External traffic may reach the guest only if additional routing entires are added. The routed mode operates at Layer 3 of the OSI networking model.
It is possible to use multiple physical network interfaces on the virtualization host by joining them together with a bond. The bond is then added to the bridge. For more details, see network bonding.
Bridged Mode
In bridged mode, the guests are connected to a bridge device that is also connected directly to a physical ethernet device connected to the local ethernet. This makes the guests directly visible on the physical network, as being part of the same subnet as the virtualization host, and thus enables incoming connections, but does not require any extra routing table entries. All other physical machines on the same physical network are aware of the virtual machines at MAC address level, and they can access them. Bridging operates on Layer 2 of the OSI networking model.
Use cases for bridged mode:
- When the guest virtual machines need to be deployed in an existing network alongside virtualization hosts and other physical machines, and they should appear no different to the end user.
- When the guests need to be deployed without making any changes to the existing physical network configuration settings.
- When the guests must be easily accessible from an existing physical network and they must use already deployed services.
- When the guests must be connected to an existing network where VLANs are used.
Isolated Mode
If the libvirt virtual network switch is configured to run in isolated mode, the guest virtual machines can communicate with each other and with the virtualization host, but the traffic will not pass outside of the virtualization host, not can they receive external traffic. The guests still receive their addresses via DHCP from dnsmasq, and send their DNS queries to the same dnsmasq instance, which may resolve external names, but the resolved IP addresses won't be accessible.
libvirt Network Filtering
Organizatorium
- Relationship to Open vSwitch