If your server has an IPv6 address, an IPv4-only firewall leaves half the door open. ufw handles both, but only when one setting says so.
Check the file first:
grep IPV6 /etc/default/ufw
Ubuntu ships with IPV6=yes, but a cloud image or an old setup script may have switched it off. If it says no, change it and reload:
sudo sed -i 's/^IPV6=no/IPV6=yes/' /etc/default/ufw
sudo ufw reload
sudo ufw status
With IPv6 enabled, every rule you add without a specific address gets a second copy marked (v6) in ufw status. That’s how you can tell at a glance it works: no (v6) lines while the server has a public IPv6 address means trouble.
Rules you added while IPv6 was off don’t get a v6 copy afterwards. Delete them and add them again after the change, or add the v6 versions by hand.
I’d think twice before switching it off, though. The manual says that with IPV6=no, ufw only accepts IPv6 on the loopback interface. On a machine that needs IPv6 for something, like updates over a v6-only network, switching it off can quietly break things. Test from outside with an IPv6 address afterwards, for example with nmap -6.
Further reading: ufw(8) manual page