If you don't need to do so over and over again, one way is to use the viewer like so:
host$ virt-viewer my_vm
Then you get access to the normal Linux console or X-Windows. You can then log in and in X-Windows start a terminal and type something like:
guest$ ip address
Once done with the viewer, you can just close that window. It won't hurt the VM, it just hides the console.
This is, of course, not practical since you cannot script such.
Unfortunately, for me the virsh domifaddr my_vm does not work:
host$ virsh domifaddr my_vm
Name MAC address Protocol Address
-------------------------------------------------------------------------------
The table remains empty...
So, to help with a more permanent solution, I use a static IP address by doing so:
host$ virsh net-update default add ip-dhcp-host \
"<host mac='52:54:00:11:22:33' name='buildserver' ip='192.168.122.123'/>" \
--config
Then, if the VM is running, I complete stop it (i.e. sudo init 0 using the console in the virt-viewer). Finally, I restart the VM and assuming I did not type the wrong MAC or static IP address, I can now do:
host$ ssh 192.168.122.123
(Obviously, it takes a few seconds to boot, so give the VM time to do that before trying to ssh into it.)
error: internal error: character device console0 is not using a PTY– Dave Ankin Jun 20 '22 at 08:12virsh consoleI had to provide the password, which I am totally unaware of. – s3cret Aug 09 '23 at 01:52