Curl not working in HA OS running on KVM virtual machine

I migrated my Home Assistant from a RPi4 to a KVM virtual machine using the instructions here:

HA OS in KVM

Everything works except I cannot get the curl command to run. I have several shell commands that use curl to trigger sirens on my poe cameras. None of them work. I can successfully ping the cameras from the HA web terminal so I know that HA can reach the cameras. However, curl is unable to reach the cameras. I am puzzled because this worked fine when HA was running on the RPi4.

For example, this is one of the shell commands in my configuration.yaml file that no longer works:

rear_south_lights_on: curl --digest -g "http://username:[email protected]/cgi-bin/coaxialControlIO.cgi?action=control&channel=1&info[0].Type=1&info[0].IO=1"

But I am able to ping 192.168.50.29 successful from the HA terminal. When I use this curl command I get the following error message:

curl: (28) Failed to connect to 192.168.50.29 port 80 after 131128 ms: Couldn't connect to server

Does anyone have any thoughts about how to solve this problem?

I found the source of the problem. My KVM host computer has two network interfaces and a firewall created by ufw. When I installed the HA OS on the KVM guest computer, I edited the /etc/ufw/before.rules to forward traffic on one of interfaces, but not the other. The second interfaces connects to the network with the cameras. To solve my problem, I did the following:

  1. First I created new forwarding rules in /etc/ufw/before.rules to allow traffic on network interface connecting to 192.168.50.0/24 and restarted ufw.

  2. Because I have two network interfaces, I specified which interface to use in the curl command by adding --interface <my_interface> where “<my_interface>” is the interface name show using ip a.