Set up network interfaces in Ubuntu for KVM virtual machine
Here is a more detailed walkthrough of bridging:
Follow these steps on the kvm server:
sudo stop network-manager
echo "manual" | sudo tee /etc/init/network-manager.override
That will disable your network-manager and prevent it from restarting.
next we work on the interface config, starting by taking the interface down:
ifdown eth0
edit "/etc/network/interfaces" and find the physical interface, likely eth0
You need to replace the eth0 interface information, to make it look like the following:
auto br0
iface br0 inet static
address XXX.XXX.X.X
netmask XXX.XXX.XXX.x
network XXX.XXX.X.X
broadcast XXX.XXX.XXX.X
gateway XXX.XXX.X.X
bridge_ports eth0
bridge_stp on
bridge_maxwait 0
You shoudl be able to then bring back your adapter with:
ifup br0
you also need to add the following to your '/etc/sysctl.conf' settings
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
and load settings with
sysctl -p /etc/sysctl.conf
Also add the line's
/sbin/sysctl -p /etc/sysctl.conf
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
to your '/etc/rc.local' file, just before the "exit 0" line to ensure these effects start at boot.
run brctl show
and look for a br0 line that shows the interface eth0. This is now a bridgeable device.
You now need to configure your guest VM's to point to this bridge. on your guests definition XML files
virsch edit <name of guest VM>
You need to edit the interface section to look similar to:
<interface type='bridge'>
<source bridge='br0'/>
<mac address='<YOUR MAC ADDRESS>'/>
<model type='virtio'/> # try this if you experience problems with VLANs
</interface>
Your devices should now be bridged. You will still need to configure IP addresses on the machines themselves correctly
Also after having gone through all the other pages for information for this. I also found this nice little tutorial that may be of help in understanding everything:
Related videos on Youtube
andreas
Updated on September 18, 2022Comments
-
andreas over 1 year
I am currently renting an
Ubuntu server
. On this machine I would like to run virtual machines usingKVM
. For some web access I have installedKimchi
, a very simple html5-based KVM management tool.Anyway I have problems setting up the networking for the virtual machines. At the moment I have one main IP and multiple additional IPs. The main IP is reserved for the host so I can access it per SSH etc. Please note that the host server is directly connected to the internet with this public IP, there is nothing in between.
Obviously now I would like to make the first virtual machine use one of the additional IPs.
This is
/etc/network/interfaces
so far:auto lo iface lo inet loopback # device: eth0 auto eth0 iface eth0 inet static address 1**.***.***.**6 broadcast 1**.***.***.**1 netmask 2**.***.***.**2 gateway 1**.***.***.**9 # default route to access subnet up route add -net 1**.***.***.**8 netmask 2**.***.***.**2 gw 1**.***.***.**9 eth0
The Kimchi web administration gives me the following options. I can create a new network which can be attached to a virtual machine:
How would I need to set up in order to let a virtual machine use an additional IP automatically?
-
andreas over 9 yearsI have only one physical network device (LAN) but multiple IPs. It would help me a lot if you could get into a bit more details in the
interfaces
file, I did not really understand how to place my two IPs in there. Thanks a lot! -
Gravy over 9 years@andreas Added some more clarified information. The following link may also prove usefull: wiki.libvirt.org/page/Networking