KVM 可以从主机而不是其他计算机进行 ssh

KVM 可以从主机而不是其他计算机进行 ssh

我已经在服务器上设置了 kvm/quemu。我按照指南操作,一切正常,但有一个例外。我只能通过运行 kvm 的服务器 ssh 到虚拟机。如果我使用笔记本电脑,则无法连接。我必须先 ssh 到服务器,然后再到虚拟机。

服务器 Ubuntu 18.04 服务器

这是服务器上的 /etc/network/interfaces。

源 /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# primary network interface
#auto eth0
#iface eth0 inet manual
#       address 192.168.1.100
#       netmask 255.255.255.0
#       dns-nameservers 8.8.8.8


#bridge
auto br0
iface br0 inet static
        address 192.168.1.100
        netmask 255.255.224.0
        gateway 192.168.1.1
        dns-nameserver 192.168.100.1 8.8.8.8
        bridge_ports eth0
        bridge_stp n
        bridge_fd 0
        bridge_maxwait 0



br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                                            
        inet 192.168.1.100  netmask 255.255.224.0  broadcast 192.168.31.255                                          
        ether 0e:37:a0:d5:da:e5  txqueuelen 1000  (Ethernet)                                                         
        RX packets 0  bytes 0 (0.0 B)                                                                                
        RX errors 0  dropped 0  overruns 0  frame 0                                                                  
        TX packets 0  bytes 0 (0.0 B)                                                                                
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                   

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500                                                                
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255                                               
        ether 02:42:ac:48:67:60  txqueuelen 0  (Ethernet)                                                            
        RX packets 0  bytes 0 (0.0 B)                                                                                
        RX errors 0  dropped 0  overruns 0  frame 0                                                                  
        TX packets 0  bytes 0 (0.0 B)                                                                                
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                   

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                                           
        inet 192.168.1.7  netmask 255.255.255.0  broadcast 192.168.1.255                                             
        ether 78:2b:cb:03:27:5c  txqueuelen 1000  (Ethernet)                                                         
        RX packets 209192  bytes 21456278 (21.4 MB)                                                                  
        RX errors 0  dropped 1400  overruns 0  frame 0                                                               
        TX packets 1220945  bytes 1689016362 (1.6 GB)                                                                
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                   

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536                                                                         
        inet 127.0.0.1  netmask 255.0.0.0                                                                            
        loop  txqueuelen 1000  (Local Loopback)                                                                      
        RX packets 350787  bytes 5953177436 (5.9 GB)                                                                 
        RX errors 0  dropped 0  overruns 0  frame 0                                                                  
        TX packets 350787  bytes 5953177436 (5.9 GB)                                                                 
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                   

virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                                         
        inet 192.168.100.1  netmask 255.255.255.0  broadcast 192.168.100.255                                         
        ether 52:54:00:81:56:35  txqueuelen 1000  (Ethernet)                                                         
        RX packets 4662  bytes 313603 (313.6 KB)                                                                     
        RX errors 0  dropped 41  overruns 0  frame 0                                                                 
        TX packets 2177  bytes 228116 (228.1 KB)                                                                     
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                   

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                                          
        ether fe:54:00:de:c7:b6  txqueuelen 1000  (Ethernet)                                                         
        RX packets 4223  bytes 336843 (336.8 KB)                                                                     
        RX errors 0  dropped 0  overruns 0  frame 0                                                                  
        TX packets 24991  bytes 1402572 (1.4 MB)                                                                     
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                   

Virsh 编辑 16

<domain type='qemu'>
  <name>ubuntu18.04</name>
  <uuid>bf380e27-73bf-4633-b69a-4b04cae4d0ab</uuid>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-bionic'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <vmport state='off'/>
  </features>
  <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>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/mnt/md1/vm/images/ubuntu18.04.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <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'>
      <master startport='2'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
        </controller>
        <controller type='usb' index='0' model='ich9-uhci3'>
          <master startport='4'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
        </controller>
        <controller type='pci' index='0' model='pci-root'/>
        <controller type='ide' index='0'>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
        </controller>
        <controller type='virtio-serial' index='0'>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
        </controller>
        <interface type='bridge'>
          <mac address='52:54:00:de:c7:b6'/>
          <source bridge='br0'/>
          <model type='virtio'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
        </interface>
        <serial type='pty'>
          <target type='isa-serial' port='0'>
            <model name='isa-serial'/>
          </target>
        </serial>
        <console type='pty'>
          <target type='serial' port='0'/>
        </console>
        <channel type='spicevmc'>
          <target type='virtio' name='com.redhat.spice.0'/>
          <address type='virtio-serial' controller='0' bus='0' port='1'/>
        </channel>
        <input type='tablet' bus='usb'>
          <address type='usb' bus='0' port='1'/>
        </input>
        <input type='mouse' bus='ps2'/>
        <input type='keyboard' bus='ps2'/>
        <graphics type='spice' autoport='yes'>
          <listen type='address'/>
        </graphics>
        <sound model='ich6'>
          <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'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
        </video>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='2'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='3'/>
    </redirdev>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
  </devices>
</domain>

进入 eno1 后,我失去了 ssh 访问权限。我尝试输入除 eno1 之外的任何字符串,结果相同。例如“bridge_ports mycatisbadass6969”。我猜 bridge_ports 区域是罪魁祸首。有什么建议吗?

笔记本电脑 Ubuntu 18.04 桌面

笔记本电脑的ifconfig

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::eb74:44f9:ec1e:5c64  prefixlen 64  scopeid 0x20<link>
        ether ac:22:0b:50:ae:ea  txqueuelen 1000  (Ethernet)
        RX packets 1350919  bytes 1948697230 (1.9 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 328633  bytes 28035898 (28.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf7b00000-f7b20000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 6029  bytes 566246 (566.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6029  bytes 566246 (566.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:a3:f6:29  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

/etc/网络/接口

auto lo
iface lo inet loopback

虚拟机Ubuntu18.04服务器

ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.147  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::5054:ff:fede:c7b6  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:de:c7:b6  txqueuelen 1000  (Ethernet)
        RX packets 278  bytes 24506 (24.5 KB)
        RX errors 0  dropped 119  overruns 0  frame 0
        TX packets 169  bytes 17083 (17.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 284  bytes 21556 (21.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 284  bytes 21556 (21.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

我变了

<interface type='network'>
  <source network='default'/>
</interface>

 <interface type='bridge'>
  <source bridge='br0'/>
</interface>

有适配器 lo..ens3 适配器

此外,我在修改 sudo /etc/inint.d/network restart 时重启了数千次网络接口

编辑...我发现运行下面这个可以让我使用适配器。仍然无法直接 ssh 到虚拟机

sudo ip addr flush dev br0 
sudo ip addr flush dev eno1

相关内容