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 from a subnet to one port keeps a service on your LAN

Ufw
~/tips/tip-ufw-allow-subnet-to-port

sudo ufw allow from 192.168.1.0/24 to any port 5432 proto tcp

Opens a port only to one source network instead of to everyone.

I rarely want a port open to the whole internet. A rule with a source network gives access to only the machines I name.

sudo ufw allow from 192.168.1.0/24 to any port 5432 proto tcp

The long form is allow from SOURCE to DEST port PORT proto PROTOCOL. Here only the 192.168.1.0/24 network can reach PostgreSQL, as long as the default policy for incoming traffic is deny. The proto part is required when you name a port range and useful to limit the rule to TCP or UDP. Check the result with sudo ufw status, where the source appears in the From column.

Further reading: ufw 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