QEMU 与 KVM:无法在主机和客户机之间 ping 或 SSH

QEMU 与 KVM:无法在主机和客户机之间 ping 或 SSH

编辑:由于macvtap无法用于主机和客户机之间的通信,我尝试使用bridge,但主机上没有互联网,并且ping仍然ssh不起作用。

这就是我创建的方式bridge

nmcli connection add type bridge ifname br0

Output:
Connection 'bridge-br0' (bf1406b0-4ea8-4338-9edc-0f58fd019bec) successfully added.


nmcli con add type ethernet con-name br-slave-1 ifname enp0s25 master br0

nmcli con add type ethernet con-name br-slave-1 ifname enp0s25 master br0

nmcli con modify bridge-br0 bridge.stp no

nmcli connection add type ethernet ifname  bridge-br0  ipv4.method auto

Output:
Connection 'ethernet-bridge-br0' (6c2c5495-6e43-4cd5-a574-014042987781) successfully added.


After reboot:

nmcli con show

NAME                       UUID                                  TYPE      DEVICE  
bridge-br0                 bf1406b0-4ea8-4338-9edc-0f58fd019bec  bridge    br0     
br-slave-1                 a998c09f-5f46-4586-b654-cdfa6a21dca5  ethernet  enp0s25 
ethernet-bridge-br0        6c2c5495-6e43-4cd5-a574-014042987781  ethernet  --      
Wired connection 1         8559f62b-0cb9-3935-ba65-b6d57c0043c8  ethernet  --      

现在如果我断开连接br-slave-1

nmcli con down br-slave-1

我恢复了主机上的互联网连接,但客户机上却没有互联网连接,并且 ping 仍然不工作

那么在使用 qemu 和 kvm 时,有没有办法ssh在主机和客户机之间使用,使用nmcliNetworkManager GUI?非常感谢。

笔记:由于我需要断断续续地使用几个不同的无线网络,我喜欢远离netplannetwork interfaces,因此我尝试使用或来设置nmcli桥接NetworkManager GUI

原始帖子

我正在尝试从主机通过 SSH 进入客户机。主机和客户机都是 Ubuntu MATE 21.04。

互联网在主机和客户机上均可正常运行。

IP 地址:

(1) Router: Asus RT AC68U > 192.168.1.1
(2) Host: Ubuntu MATE 21.04 > 192.168.1.106
(3) Guest: Ubuntu MATE 21.04 > 192.168.1.139

防火墙已在所有三个设备上被禁用/停止:

(1) Router: Asus RT AC68U > SPI Firewall > Disabled
(2) Host: Ubuntu MATE 21.04 > sudo systemctl stop nftables
(3) Guest: Ubuntu MATE 21.04 > sudo systemctl stop nftables

当我尝试时ssh-copy-id,出现此错误:No route to host

ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: ERROR: ssh: connect to host 192.168.1.139 port 22: No route to host

所以我尝试了ping(无论哪种方式都不起作用;“主人对客人”或“客人对主人”):

ping 192.168.1.139

PING 192.168.1.139 (192.168.1.139) 56(84) bytes of data.
From 192.168.1.106 icmp_seq=1 Destination Host Unreachable
From 192.168.1.106 icmp_seq=2 Destination Host Unreachable

但是,ping无论是从“主机到路由器”还是“访客到路由器”都可以工作:

ping从主机到路由器:

ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.400 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.339 ms

ping从客户机到路由器:

ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.651 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.625 ms

主机和客户机通过网络桥接器连接br0,这是我使用 Netwrok Manager GUI 创建的。网桥br0有两个“桥接连接”,br0 slave 1br0 slave 2

Enable STP (spanning Tree Protocol是“未选中”的。尽管我“选中”了它,但并没有什么不同。

我认为其他详细信息可能会有帮助:

sudo nano /etc/libvirt/qemu/networks/host-bridge.xml

<network>
  <name>host-bridge</name>
  <uuid>0ae7be62-9f9e-4346-9309-88985dd0f5ad</uuid>
  <forward mode='bridge'/>
  <bridge name='br0'/>
</network>


virsh net-list --all

 Name          State    Autostart   Persistent
------------------------------------------------
 host-bridge   active   yes         yes

主机上ip a的结果:ip r

ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether e0:69:95:4d:7c:9c brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.106/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s25
       valid_lft 599784sec preferred_lft 599784sec
    inet 192.168.1.104/24 brd 192.168.1.255 scope global secondary noprefixroute enp0s25
       valid_lft forever preferred_lft forever
3: wlxd0374547816a: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether d0:37:45:47:81:6a brd ff:ff:ff:ff:ff:ff
4: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 96:d5:ab:3c:a7:e8 brd ff:ff:ff:ff:ff:ff
7: macvtap2@enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 500
    link/ether 52:54:00:1f:6a:cd brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.140/24 brd 192.168.1.255 scope global noprefixroute macvtap2
       valid_lft forever preferred_lft forever

ip r       

default via 192.168.1.1 dev enp0s25 proto dhcp src 192.168.1.104 metric 202 
default via 192.168.1.1 dev macvtap2 proto dhcp src 192.168.1.140 metric 207 
169.254.0.0/16 dev macvtap2 scope link metric 1000 
192.168.1.0/24 dev enp0s25 proto dhcp scope link src 192.168.1.104 metric 202 
192.168.1.0/24 dev macvtap2 proto dhcp scope link src 192.168.1.140 metric 207 

客户机上ip a的结果:ip r

ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1f:6a:cd brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.139/24 brd 192.168.1.255 scope global dynamic noprefixroute enp2s0
       valid_lft 603989sec preferred_lft 603989sec
    inet6 fe80::d316:3db7:9af5:8d0c/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

ip r

default via 192.168.1.1 dev enp2s0 proto dhcp metric 100 
169.254.0.0/16 dev enp2s0 scope link metric 1000 
192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.139 metric 100 

客户机的 NIC 详细信息(来自虚拟机管理器):

Virtual Network Interface:

Network source: Macvtap device
Device name: enp0s25
Device model: virtio

XML:
<interface type="direct">
  <mac address="52:54:00:1f:6a:cd"/>
  <source dev="enp0s25" mode="bridge"/>
  <target dev="macvtap2"/>
  <model type="virtio"/>
  <alias name="net0"/>
  <address type="pci" domain="0x0000" bus="0x02" slot="0x00" function="0x0"/>
</interface>

操作系统:Ubuntu MATE 21.04

qemu:1:5.2+dfsg-9ubuntu3

桥接实用程序:1.6-5ubuntu1

virt-manager:1:3.2.0-3

libvirt 守护进程:7.0.0-2ubuntu2

提前致谢。

編輯-1:

brctl show br0

bridge name bridge id       STP enabled interfaces
br0     8000.96d5ab3ca7e8   no      

答案1

我原本希望您的虚拟机使用您的网桥 br0 作为所需的通信方法。我正在运行 3 个虚拟机并得到:

doug@s19:~$ brctl show br0
bridge name     bridge id               STP enabled     interfaces
br0             8000.3c7c3f0d9983       no              enp3s0
                                                        vnet0
                                                        vnet1
                                                        vnet2

在主机上:

doug@s19:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
    link/ether 3c:7c:3f:0d:99:83 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 3c:7c:3f:0d:99:83 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.136/24 brd 192.168.111.255 scope global dynamic br0
       valid_lft 45219sec preferred_lft 45219sec
4: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
    link/ether fe:54:00:22:2f:dc brd ff:ff:ff:ff:ff:ff
5: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
    link/ether fe:54:00:60:ea:3e brd ff:ff:ff:ff:ff:ff
6: vnet2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
    link/ether fe:54:00:60:ea:5e brd ff:ff:ff:ff:ff:ff

使用我的 netplan 网络文件/etc/netplan/01-netcfg.yaml

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: no
  bridges:
    br0:
      interfaces: [ enp3s0 ]
      dhcp4: yes

以及虚拟机的.xml 定义文件之一的相关部分:

<interface type='bridge'>
  <mac address='52:54:00:22:2f:dc'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>

相关内容