Allow a port through the firewall with ufw
Add a UFW rule to permit inbound traffic on a TCP or UDP port, such as SSH on port 22.
01Command
$ sudo ufw allow 22/tcp02What it does
Rules accept port/protocol (80/tcp), service names from /etc/services (ufw allow ssh), or app profiles (ufw allow 'Nginx Full'); omit the protocol to allow both TCP and UDP. By default an allow rule opens the port on all interfaces — restrict it to a subnet with ufw allow from 192.168.1.0/24 to any port 22. Order matters: first matching rule wins, and ufw status numbered plus ufw delete <n> lets you remove by position. Verify with sudo ufw status verbose; only rules while ufw is enabled are enforced.
03Risk
04Undo
$ sudo ufw delete allow 22/tcp05Sources
- UncomplicatedFirewall - Ubuntu WikiEvidence: The Ubuntu UFW wiki describes enabling the firewall with ufw enable and adding allow rules by port and protocol.
- ufw(8) — program for managing a netfilter firewallEvidence: The ufw manual documents 'ufw allow' rules with PORT/PROTO syntax such as 22/tcp and matching 'ufw delete allow' to remove them.
Last verified: 2026-09-17 · Category: Security & Privacy
06Related solutions
One command that prints every interface with its state and IPv4/IPv6 addresses in a short table — the modern, memorable replacement for digging through `ifconfig` or the verbose `ip addr` output.
Generate a modern Ed25519 public/private key pair in ~/.ssh for authenticating to servers and Git platforms without passwords.
Add or remove read, write, and execute permission for the owner, group, or others using symbolic or octal modes.