Thursday, March 26, 2020

ssh into libvirt guest

Libvirt sets up NAT mode per default allowing guests to communicate, for example, with the internet, with each other and with the host. A host interface vnetX will be created and normally an IP will be assigned automatically.

# virsh domifaddr vm
 Name       MAC address          Protocol     Address
 vnet0      52:54:00:6f:dc:90    ipv4

# virsh dumpxml --inactive vm
    <interface type="network">
      <mac address="52:54:00:6f:dc:90">
      <source network="default"></source>
      <model type="virtio">
      <address bus="0x00" domain="0x0000" function="0x0" slot="0x03" type="pci">

However, vnetX won't get the IP assigned really, that's not how it's intended. So, per default neither the ip nor any name are available to ssh

What you can do instead is use the NSS module libvirt-nss.

If you want to easily ssh into the guest using its libvirt name, set
# /etc/nsswitch.conf:
hosts:       files libvirt_guest dns
and make sure to have the correct sshd configuration in your guest.

No comments:

Post a Comment