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 allow 53 without /tcp opens both TCP and UDP

Ufw
~/tips/tip-ufw-allow-port-without-proto

sudo ufw allow 8080

Shows why adding the protocol to a port rule keeps the opening as small as needed.

It’s easy to type ufw allow 8080 and move on. Without a protocol, ufw opens that port for TCP and UDP both, which is often twice what you need.

Compare the two:

sudo ufw allow 8080
sudo ufw allow 8080/tcp
sudo ufw status

The first rule shows up as 8080 in the status, the second as 8080/tcp. The manual uses port 53 as its example: ufw allow 53 allows both TCP and UDP on port 53 to any address on the host. For DNS that is correct, since DNS really does use both. For a web app, a database or an admin panel it’s just an extra open port.

An open UDP port with nothing listening does little harm today. The problem comes later, when some service starts listening on that UDP port and is reachable right away because of a rule you forgot about.

I’d always write the protocol. To fix an existing rule, delete it and add the narrower one:

sudo ufw delete allow 8080
sudo ufw allow 8080/tcp

Application profiles have the same issue. ufw app info shows which protocols a profile opens, so look before you trust the name. And for services that really need both, like DNS, leaving it out is fine as long as you meant it.

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 sudo ufw show listening All Ufw tips (32) All topics

Link