How do I list virsh networks without sudo?

Solution 1:

It appears that:

If not explicitly stated, the virsh binary uses the 'qemu:///session' URI (at least under debian).

Therefore, not only virsh net-list, but practically any command, including virsh list, behaved differently when running with sudo. In other words, virsh net-list was using user's scope instead of global ones.

This makes sense; trying to create the default connection and then starting it led to “Network is already in use by interface virbr0” error—without knowing it, I was starting a second connection named “default”, while one was already running.

The solution is straightforward:

virsh --connect qemu:///system net-list

does what I was expecting it to do, while:

virsh net-list


Why is Ubuntu machine not having the issue?

According to the documentation:

If virsh finds the environment variable VIRSH_DEFAULT_CONNECT_URI set, it will try this URI by default. Use of this environment variable is, however, deprecated now that libvirt supports LIBVIRT_DEFAULT_URI itself.

It appears, indeed, that on Ubuntu machine, the second variable was defined:


ubuntu:~$ echo $LIBVIRT_DEFAULT_URI

On Debian machine, on the other hand, none of those variables are set:


debian:~$ echo $LIBVIRT_DEFAULT_URI

Setting one of those variables to qemu:///system would probably work, but, well, it's easier to specify the connection string directly in virsh command (at least when writing a script).

Solution 2:

uncomment this line in file /etc/libvirt/libvirt.conf

uri_default = "qemu:///system"

was enough for me in fedora 29 .

Edit: as it says here for non root users that file also needs to be in $XDG_CONFIG_HOME/libvirt/libvirt.conf

which in my case is:


so i copy the file there (on my fresh install) and now virsh net-list works as a non-root user and no need to espicify --connect