KVM with VDE
From Gentoo Linux Wiki
| Please format this article according to the Style Guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article.
Reason(s):
|
Once you have setup a KVM system, you don't have UDP support yet. Some people choose to use VDE. This way you also need just one TAP interface.
VDE stands for Virtual Distributed Ethernet and is exactly what the name implies: a virtual switch. You can connect VDEs between physical machines and run multiple VLANs, separate routes, etc. This way you won't have to bother about VM configuration again - just connect them to a virtual switch which has DHCP and DNS services connected.
Contents |
[edit] Kernel configuration
First, get your kernel on the host (real) machine up to speed for networking with virtual machines:
| Linux Kernel Configuration: VDE kernel config |
Device drivers --->
Network device support --->
[M] Universal TUN/TAP device driver support
Networking support --->
Networking options --->
Network packet filtering framework (Netfilter) --->
Core Netfilter Configuration --->
<*> Netfilter connection tracking support
IP: Netfilter Confiuration --->
<*> IPv4 connection tracking support (required for NAT)
<*> IP tables support (required for filtering/masq/NAT)
<*> Full NAT
<*> MASQUERADE target support
|
Rebuild and install your kernel.
[edit] Installation
All but the last of the following commands are done on the host (real) machine:
Install net-misc/vde.
Load all the modules you'll need:
Create a hub for VDE. The '-d' option make the vde_switch run in daemon mode.
Now that we have a hub, lets give an ip to our tap interface, netmask, etc and turn it on:
If you haven't already turned on forwarding now is a good time:
Now configure iptables to NAT your vms outbound assuming your real live interface is eth0:
I also had to allow all forwarding in iptables:
Depending to your iptable rules, you may also need to allow your virtual machine to connect to your host machine through tap0 interface. Otherwise, your vm will not be able to lease IP from the dnsmasq tool running on your host.
You'll need some dns/dhcp for your guest operating system virtual machines. emerge dnsmasq if you don't already have it
Run it with some options to give ip ranges, interfaces, logging, default domain names:
Now finally, start something! A bootable CD is a good test.
You can monitor it's network traffic in another session with tcpdump:
Your guest OS should get an ip automagically through dhcp, be assigned default resolv.conf parameters, etc. If you can ping something on the internets you're good! (This is the only command here that is run inside the guest OS in the virtual machine)
[edit] Alternative Method
If you would rather not mess around with kernel configs, TUN, iptables and dnsmasq, then you can achieve the same result with the following two commands instead;
Then start your virtual machines with this command;
