brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ufw show listening matches open ports to the rules that cover them

Ufw
~/tips/tip-ufw-show-listening

sudo ufw show listening

Lists listening ports with their program and the ufw rule that applies.

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

More Ufw tips sudo ufw app update all sudo ufw show raw sudo ufw allow to 10.0.0.1 proto esp sudo ufw allow to 224.0.0.0/24 from 10.0.0.1 proto vrrp grep IPV6 /etc/default/ufw All Ufw tips (32) All topics

Link