ufw status shows your rules, and ss shows what is listening. ufw show listening puts the two side by side, which is the comparison I actually want.
Run it as root:
sudo ufw show listening
For each TCP port in the listening state and each open UDP port, it prints the address the service is bound to and the program behind it. Under a port that matches a rule, it shows that rule with its number, the same number ufw status numbered uses.
Two things jump out when you read it. A port with no rule under it is blocked by your default policy, which is fine if you meant that and confusing if you just installed something and wonder why nobody can reach it. And a rule with nothing listening behind it is a leftover, an open door for a service that may come back one day without you thinking about it.
The address column matters too. A service bound to 127.0.0.1 can’t be reached from outside whatever ufw says, while one on 0.0.0.0 or * relies fully on the firewall.
It has a blind spot: ports published by Docker. Docker writes its own iptables rules that bypass ufw, so a container port can show up here without a ufw rule and still be wide open. For those, check docker ps and test from another machine.
Further reading: ufw(8) manual page