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: read a [UFW BLOCK] line by its SRC, DPT and PROTO fields

Ufw
~/tips/tip-ufw-block-log-fields

sudo journalctl -k --since '1 hour ago' | grep 'UFW BLOCK'

Explains the fields in a ufw log line so you can see what was blocked.

A ufw log line looks like a wall of capital letters. Only a handful of fields matter, and once you know them you can see in a second what got blocked and why.

Pull the recent blocks from the kernel log:

sudo journalctl -k --since '1 hour ago' | grep 'UFW BLOCK'

A typical line contains IN=eth0 OUT= ... SRC=203.0.113.25 DST=192.0.2.10 ... PROTO=TCP SPT=51234 DPT=3389. Here is how I’d read it:

IN is the interface the packet came in on, and an empty OUT means it was meant for this machine. SRC is who sent it and DST which of your addresses it was aimed at. PROTO is TCP, UDP or ICMP. DPT, the destination port, tells you which service someone tried to reach. SPT, the source port, is usually random and not interesting.

To see which ports get knocked on most:

sudo journalctl -k | grep 'UFW BLOCK' | grep -o 'DPT=[0-9]*' | sort | uniq -c | sort -rn | head

Don’t panic over the volume. Every server on the internet gets scanned all day, and a block line means the firewall did its job. What I would look for is a block on a port I expected to be open, which points to a missing rule, or blocks with an OUT= interface set, which means traffic leaving or passing through the box was stopped.

Further reading: ufw(8) manual page, Ubuntu wiki: UFW

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