You must stop the libvirtd service (systemctl stop libvirtd) and then start libvirtd-tcp.socket (systemctl start libvirtd-tcp.socket) and then start the libvirtd service (systemctl start libvirtd) to listen to tcp normally.
It looks like you’ve correctly configured libvirtd.conf to enable TCP connections, but TCP listening doesn’t start automatically after a reboot. That’s because libvirtd-tcp.socket is not enabled to start at boot time.
systemctl enable libvirtd-tcp.socket has been executed before restarting. If you do not stop the libvirtd service, restart libvirtd-tcp.socketsystemctl restart libvirtd-tcp.socket will prompt an error that cannot be started. I personally feel that there is a problem with the configuration or the libvirtd service startup sequence or dependency.
It seems that you have to add dependencies for libvritd.service. You can create the following file: /etc/systemd/system/libvirtd.service.d/override.conf
Than run systemctl daemon-reload. You can validate the config applies by checking if the new dependencies are listed with systemctl cat libvirtd.service.
The problem was solved through the method you introduced. But there are still some doubts. 1. Does this problem only occur on rocky or radhat series? 2. Actually, I have configured it on different machines before, that is, by default, only the /etc/libvirt/libvirtd.conf file is modified. For the same system version, some machines can automatically start tcp listening no matter how they restart, while others cannot. 3. Why do such a regular requirement have problems or are not considered, and no official documents mention it.
I suppose you could install RHEL and find out if the problem occurs there? Since Rocky is based on RHEL 1:1 I expect yes it will be a problem there as well.
Which machines? What Linux OS? What versions of qemu and libvirt packages? Lots of different variables as to why they work or not work based on package versions, configuration. Whether the machine has been hardened with CIS profiles, or selinux causing issues.
See above, too many variables based on OS, package versions, configuration, hardening or selinux or other potential issues. People may or may not use it, and hence the lack of documentation for it. For example here: Setting Up libvirt on Rocky Linux - Documentation or even libvirt website that shows how to configure by referencing /etc/sysconfig/libvirtd which doesn’t exist in Rocky 9 or higher anyway. So out-of-date docs by libvirt themselves. BTW, you could if you wanted contribute and amend the Rocky documentation to include such items as enabling TCP if you feel it needs documenting.
The same machine refers to installing the same Rocky 9 version, the same version of libvirtd, the same modified configuration file, and the running results are different.
Actually, as I described earlier, guessing that the problem should be caused by dependency and startup sequence. But I think libvirtd needs to enable tcp listening is not a niche requirement, and service or script developers should be able to consider it, or such bugs should not occur and there is no additional hint