How can I ssh to a virtual machine in "Boxes"?

I have set up a virtual machine in Boxes, using the downloaded Leap-16.0-offline-installer-x86_64.install.iso (Boxes wouldn’t find the installer online). The setup went smooth and swift, but I don’t see how I can ssh to that VM.
I installed sshd like this:

zypper install openssh
systemctl enable sshd
systemctl start sshd
firewall-cmd --add-service=ssh --permanent
firewall-cmd --reload

and I can ssh from the VM to other machines. When I run ip address I see that the VM has 10.0.2.15, but that IP is not accessible from the host PC or other PCs in the local network.

Is there a way to have the VM get an IP from the local DHCP server, so that I can access it from other machines in the local network?

What is your host operating system and which hypervisor (VirtualBox, Qemu/KVM, …) are you using?

@susejunky GNOME Boxes :wink:

@kls Do you have a second interface that can be setup as a bridge device, that’s what I use here… Else some NATing, and likely sysctl config for ipv4 forwarding.

Assuming Boxes is using QEMU under the hood, this is the default address assigned by QEMU user networking backend (SLIRP). You need to setup port forwarding from host into guest in the guest configuration (or at run time using e.g. QEMU monitor).

As usual - connect the guest network interface to a bridge device on the host.

The host OS is Leap 16.0. I want to use the VM for experimenting, without messing with my working machine.

The hypervisor is Qemu (default).

This machine has only one network interface.

I found a relatively simple workaround:
On the VM:

ssh -R 2222:localhost:22 user@192.168.1.100

On the remote PC (192.168.1.100):

ssh -p 2222 user@localhost

Works fine for my tests.
Would be nice, though, if Boxes would offer an option to give the VM an IP number from the LAN. But I guess that’s not an openSUSE issue.

@kls it does allow that in the preferences to use a bridge device, I have 4 port PCIe X1 device here for VM’s, but also have USB Ethernet devices I can use as well.

I’m afraid I can’t find any “Preferences” option in the Boxes window. When I launch a VM the window gets a “three dots” button from which I can open a Preferences dialog, but that doesn’t have any options regarding the network interface.

Anyway, the reverse ssh tunnel method works for me.
I even automated it by installing autossh

sudo zypper addrepo https://download.opensuse.org/repositories/security/16.0/security.repo
sudo zypper refresh
sudo zypper install autossh

and adding

@reboot kls autossh -M 0 -f -N -R 2222:localhost:22 kls@eagle

to /etc/crontab on the VM. Also did

ssh-keygen
ssh-copy-id kls@eagle

on the VM to make autossh work without password.
Note that “kls” is my user name and “eagle” is the name of the machine from which I want to ssh to the VM.