[GELÖST] VM mit KVM, virtuelles Netzwerk funktioniert nicht

Einrichten des lokalen Netzes, Verbindung zu anderen Computern und Diensten.
Antworten
BrotherJ
Beiträge: 323
Registriert: 15.11.2018 07:56:18

[GELÖST] VM mit KVM, virtuelles Netzwerk funktioniert nicht

Beitrag von BrotherJ » 17.11.2018 19:19:52

Guten Abend,

ich bin gerade dabei auf Debian 9 eine VM mit KVM/QEMU anzulegen, dabei scheitere ich an der Netzwerkkonfiguration. Die VM kann während der Installer läuft kein DHCP-Lease abholen.
Das Netzwerk habe ich so vorbereitet:
Anlegen einer Bridge br0

Code: Alles auswählen

brctl addbr br0
brctl addif br0 enp7s0
brctl show                                                                                                                                                                                                   
bridge name     bridge id               STP enabled     interfaces                                                                                                                                                                     
br0             8000.4cedfb7a0916       no              enp7s0
Konfiguration der Bridge br0
/etc/network/interfaces

Code: Alles auswählen

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback
/etc/network/interfaces.d/br0

Code: Alles auswählen

auto br0
iface br0 inet static
        address 192.168.0.2
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1
        bridge_ports enp7s0
        bridge_fd 0
        bridge_stp yes
        bridge_maxwait 5
        dns-nameservers 192.168.0.1 8.8.8.8 8.8.4.4
        dns-search local
Wenn ich dann die VM anlegen will, scheitert der DHCP-Bezug und die Vergabe von einer festen IP mit 192.168.0.100 und dem Gateway 192.168.0.1 scheitert die Installation, weil die VM nicht auf das Internet zugreifen kann.

Code: Alles auswählen

virt-install --virt-type=kvm --name jessie --ram 2048 --vcpus=2 --os-variant=debianjessie --virt-type=kvm --hvm --cdrom=/var/lib/libvirt/boot/debian-8.10.0-amd64-netinst.iso --graphics spice --disk path=/var/lib/libvirt/images/debian-8.10.0.qcow2,size=20,bus=virtio,format=qcow2
Das ist die Datei für das virtuelle Netzwerk
/etc/libvirt/qemu/networks/br0.xml

Code: Alles auswählen

<!--                                                                                                                                                                                                                                   
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE                                                                                                                                                                
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:                                                                                                                                                          
  virsh net-edit br0                                                                                                                                                                                                                   
or other application using the libvirt API.                                                                                                                                                                                            
-->                                                                                                                                                                                                                                    

<network>
  <name>br0</name>
  <uuid>ae5110ec-89c7-4948-8d2a-657bfebb02e5</uuid>
  <forward mode='bridge'/>
  <bridge name='br0'/>
</network>
Was habe ich vergessen oder falsch gemacht?

BrotherJ
Zuletzt geändert von BrotherJ am 18.11.2018 17:55:43, insgesamt 1-mal geändert.

Benutzeravatar
habakug
Moderator
Beiträge: 4313
Registriert: 23.10.2004 13:08:41
Lizenz eigener Beiträge: MIT Lizenz

Re: VM mit KVM, virtuelles Netzwerk funktioniert nicht

Beitrag von habakug » 17.11.2018 22:21:08

Hallo,

wie ist es denn wenn du die Bridge angibst:

Code: Alles auswählen

$ virt-install [...] --network bridge=br0 [...] -d 
?

Gruss, habakug

~/.cache/virt-manager/virt-install.log
( # = root | $ = user | !! = mod ) (Vor der PN) (Debianforum-Wiki) (NoPaste)

BrotherJ
Beiträge: 323
Registriert: 15.11.2018 07:56:18

Re: VM mit KVM, virtuelles Netzwerk funktioniert nicht

Beitrag von BrotherJ » 18.11.2018 10:03:33

Vielen Dank habakug,
für den Hinweis mit den zwei Parametern. Leider erhält die VM immer noch kein DHCP-Lease und die Vergabe der festen IP führt auch nicht dazu, dass eine Verbindung zum Internet zustandekommt.
Hier der Auswurf bei dem Start von virt-install:

Code: Alles auswählen

<pool type='dir'>
  <name>images</name>
  <uuid>fe089ec1-c096-499c-a5f7-e27a330291a8</uuid>
  <capacity unit='bytes'>245949276160</capacity>
  <allocation unit='bytes'>1717129216</allocation>
  <available unit='bytes'>244232146944</available>
  <source>
  </source>
  <target>
    <path>/var/lib/libvirt/images</path>
    <permissions>
      <mode>0755</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (guest:241) Setting Guest.os_variant to 'debianjessie'
[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (virt-install:685) Guest.has_install_phase: True

Installation wird gestartet …
[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (guest:1085) Local connection, disabling spice image compression.
[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (storage:811) Creating storage volume 'debian-8.10.0.qcow2' with xml:
<volume>
  <name>debian-8.10.0.qcow2</name>
  <capacity>21474836480</capacity>
  <allocation>21474836480</allocation>
  <target>
    <format type="qcow2"/>
    <features>
      <lazy_refcounts/>
    </features>
  </target>
</volume>

[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (storage:842) Using vol create flags=1
[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (storage:875) Couldn't lookup storage volume in prog thread.
Zuweisen von 'debian-8.10.0.qcow2'                                                                                                                                                                          |  20 GB  00:00:00     
[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (storage:849) Storage volume 'debian-8.10.0.qcow2' install complete.
[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (guest:380) Generated install XML: 
<domain type="kvm">
  <name>jessie</name>
  <uuid>0c06605d-d744-4274-95f2-fe5614319994</uuid>
  <memory>2097152</memory>
  <currentMemory>2097152</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type arch="x86_64">hvm</type>
    <boot dev="cdrom"/>
    <boot dev="hd"/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <vmport state="off"/>
  </features>
  <cpu mode="custom" match="exact">
    <model>Opteron_G3</model>
  </cpu>
  <clock offset="utc">
    <timer name="rtc" tickpolicy="catchup"/>
    <timer name="pit" tickpolicy="delay"/>
    <timer name="hpet" present="no"/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled="no"/>
    <suspend-to-disk enabled="no"/>
  </pm>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/var/lib/libvirt/images/debian-8.10.0.qcow2"/>
      <target dev="vda" bus="virtio"/>
    </disk>
    <disk type="file" device="cdrom">
      <driver name="qemu" type="raw"/>
      <source file="/var/lib/libvirt/boot/debian-8.10.0-amd64-netinst.iso"/>
      <target dev="hda" bus="ide"/>
      <readonly/>
    </disk>
    <controller type="usb" index="0" model="ich9-ehci1"/>
    <controller type="usb" index="0" model="ich9-uhci1">
      <master startport="0"/>
    </controller>
    <controller type="usb" index="0" model="ich9-uhci2">
      <master startport="2"/>
    </controller>
    <controller type="usb" index="0" model="ich9-uhci3">
      <master startport="4"/>
    </controller>
    <interface type="bridge">
      <source bridge="br0"/>
      <mac address="52:54:00:91:cb:4e"/>
      <model type="virtio"/>
    </interface>
    <input type="tablet" bus="usb"/>
    <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
      <image compression="off"/>
    </graphics>
    <console type="pty"/>
    <channel type="spicevmc">
      <target type="virtio" name="com.redhat.spice.0"/>
    </channel>
    <sound model="ich6"/>
    <video>
      <model type="qxl"/>
    </video>
    <redirdev bus="usb" type="spicevmc"/>
    <redirdev bus="usb" type="spicevmc"/>
  </devices>
</domain>

[So, 18 Nov 2018 09:46:01 virt-install 15392] DEBUG (guest:381) Generated boot XML: 
<domain type="kvm">
  <name>jessie</name>
  <uuid>0c06605d-d744-4274-95f2-fe5614319994</uuid>
  <memory>2097152</memory>
  <currentMemory>2097152</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type arch="x86_64">hvm</type>
    <boot dev="hd"/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <vmport state="off"/>
  </features>
  <cpu mode="custom" match="exact">
    <model>Opteron_G3</model>
  </cpu>
  <clock offset="utc">
    <timer name="rtc" tickpolicy="catchup"/>
    <timer name="pit" tickpolicy="delay"/>
    <timer name="hpet" present="no"/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <pm>
    <suspend-to-mem enabled="no"/>
    <suspend-to-disk enabled="no"/>
  </pm>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/var/lib/libvirt/images/debian-8.10.0.qcow2"/>
      <target dev="vda" bus="virtio"/>
    </disk>
    <disk type="file" device="cdrom">
      <target dev="hda" bus="ide"/>
      <readonly/>
    </disk>
    <controller type="usb" index="0" model="ich9-ehci1"/>
    <controller type="usb" index="0" model="ich9-uhci1">
      <master startport="0"/>
    </controller>
    <controller type="usb" index="0" model="ich9-uhci2">
      <master startport="2"/>
    </controller>
    <controller type="usb" index="0" model="ich9-uhci3">
      <master startport="4"/>
    </controller>
    <interface type="bridge">
      <source bridge="br0"/>
      <mac address="52:54:00:91:cb:4e"/>
      <model type="virtio"/>
    </interface>
    <input type="tablet" bus="usb"/>
    <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
      <image compression="off"/>
    </graphics>
    <console type="pty"/>
    <channel type="spicevmc">
      <target type="virtio" name="com.redhat.spice.0"/>
    </channel>
    <sound model="ich6"/>
    <video>
      <model type="qxl"/>
    </video>
    <redirdev bus="usb" type="spicevmc"/>
    <redirdev bus="usb" type="spicevmc"/>
  </devices>
</domain>

Domain wird erstellt...                                                                                                                                                                                         |    0 B  00:00:00     
[So, 18 Nov 2018 09:46:02 virt-install 15392] DEBUG (guest:404) XML fetched from libvirt object:
<domain type='kvm' id='3'>
  <name>jessie</name>
  <uuid>0c06605d-d744-4274-95f2-fe5614319994</uuid>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.8'>hvm</type>
    <boot dev='cdrom'/>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <vmport state='off'/>
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='forbid'>Opteron_G3</model>
  </cpu>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/debian-8.10.0.qcow2'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/boot/debian-8.10.0-amd64-netinst.iso'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <alias name='usb'/>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <alias name='usb'/>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <alias name='usb'/>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <controller type='ide' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <alias name='virtio-serial0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:91:cb:4e'/>
      <source bridge='br0'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/3'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/3'>
      <source path='/dev/pts/3'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0' state='disconnected'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='tablet' bus='usb'>
      <alias name='input0'/>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'>
      <alias name='input1'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input2'/>
    </input>
    <graphics type='spice' port='5900' autoport='yes' listen='127.0.0.1'>
      <listen type='address' address='127.0.0.1'/>
      <image compression='off'/>
    </graphics>
    <sound model='ich6'>
      <alias name='sound0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
      <address type='usb' bus='0' port='2'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir1'/>
      <address type='usb' bus='0' port='3'/>
    </redirdev>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='none' model='none'/>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+64055:+64055</label>
    <imagelabel>+64055:+64055</imagelabel>
  </seclabel>
</domain>
Vielleicht mache ich auch etwas falsch bei der Netzwerkkonfiguration am Host?
Ich habe auch gelesen, dass man die DHCP-Abfrage an den externen DHCP-Server durchreichen kann, das wäre 192.168.0.1. Nur wie gebe ich das an? Ich gehe davon aus, dass KVM dnsmasq nutzt, welches auch mit dnsmasq-base installiert ist. Aber dann müsste zumindest die feste IP-Adresse funktionieren.

Viele Grüße
BrotherJ

Benutzeravatar
bluestar
Beiträge: 2334
Registriert: 26.10.2004 11:16:34
Wohnort: Rhein-Main-Gebiet

Re: VM mit KVM, virtuelles Netzwerk funktioniert nicht

Beitrag von bluestar » 18.11.2018 10:11:00

Starte mal deine VM und checke danach ein:

Code: Alles auswählen

brctl show
Ach und prüfe mal auf deinem Host, ob dort ne Firewall aktiv ist

Code: Alles auswählen

iptables-save

BrotherJ
Beiträge: 323
Registriert: 15.11.2018 07:56:18

Re: VM mit KVM, virtuelles Netzwerk funktioniert nicht

Beitrag von BrotherJ » 18.11.2018 10:39:24

Hallo,

hier die beiden Ausgaben

Code: Alles auswählen

brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.4cedfb7a0916       yes             enp7s0
                                                        vnet0
docker0         8000.02428339a441       no
und

Code: Alles auswählen

iptables-save 
# Generated by iptables-save v1.6.0 on Sun Nov 18 10:33:14 2018
*nat
:PREROUTING ACCEPT [86:13531]
:INPUT ACCEPT [21:10063]
:OUTPUT ACCEPT [2070:136770]
:POSTROUTING ACCEPT [2070:136770]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
COMMIT
# Completed on Sun Nov 18 10:33:14 2018
# Generated by iptables-save v1.6.0 on Sun Nov 18 10:33:14 2018
*filter
:INPUT ACCEPT [116107:262016514]
:FORWARD DROP [128:27386]
:OUTPUT ACCEPT [99172:192163497]
:DOCKER - [0:0]
:DOCKER-ISOLATION-STAGE-1 - [0:0]
:DOCKER-ISOLATION-STAGE-2 - [0:0]
:DOCKER-USER - [0:0]
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN
COMMIT
# Completed on Sun Nov 18 10:33:14 2018
In /etc/libvirt/qemu/networks steht als Autostart das Defaultnetzwerk

Code: Alles auswählen

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh net-edit default
or other application using the libvirt API.
-->

<network>
  <name>default</name>
  <uuid>cb513a74-6106-4a52-a170-54fcf3d25f48</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:87:1f:78'/>
  <ip address='192.168.1.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.1.2' end='192.168.1.254'/>
    </dhcp>
  </ip>
</network>
Vielleicht sollte ich das auf mein 192.168.0er Netz ändern.

Benutzeravatar
bluestar
Beiträge: 2334
Registriert: 26.10.2004 11:16:34
Wohnort: Rhein-Main-Gebiet

Re: VM mit KVM, virtuelles Netzwerk funktioniert nicht

Beitrag von bluestar » 18.11.2018 10:49:06

BrotherJ hat geschrieben: ↑ zum Beitrag ↑
18.11.2018 10:39:24
Hallo,

hier die beiden Ausgaben

Code: Alles auswählen

brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.4cedfb7a0916       yes             enp7s0
                                                        vnet0
docker0         8000.02428339a441       no
Das sieht schon mal gut aus.

Deine Firewall-Regeln hingegen nicht, ändere zum Testen mal die Default-Policy für den FORWARD-Chain von DROP auf ACCEPT.

Code: Alles auswählen

iptables -P FORWARD ACCEPT

BrotherJ
Beiträge: 323
Registriert: 15.11.2018 07:56:18

Re: VM mit KVM, virtuelles Netzwerk funktioniert nicht

Beitrag von BrotherJ » 18.11.2018 17:55:13

Vielen Dank für den Tip mit der Firewall-Regel, das hat prima geklappt.

Ich mache das hier noch vollständig, da die Firewall-Regel auch beim nächsten Start wieder vorhanden sein sollte.

Code: Alles auswählen

mkdir /etc/iptables
iptables-save > /etc/iptables/rules.v4
apt-get install iptables-persistent
Danach sollte das automatische Laden der gespeicherten iptables Rules funktionieren.

Antworten