- 49 Views
- 15/12/2025
How to Block Inbound and Outbound Ports Using UFW on Ubuntu Server
UFW (Uncomplicated Firewall) is a user-friendly firewall management tool for Ubuntu that allows administrators to easily control incoming (IN) and outgoing (OUT) network traffic using simple commands.
Blocking Inbound Ports (IN)
Block a Specific Inbound Port
Block Multiple Inbound Ports
Block a Port by Protocol
Blocking Outbound Ports (OUT) – Highly Recommended
Blocking outbound ports helps prevent spam, data exfiltration, and malware activity on compromised servers.
Block SMTP Outbound Ports
sudo ufw deny out 465
sudo ufw deny out 587
Block Outbound Traffic by Protocol
Allow Essential Services
sudo ufw allow 80 # HTTP
sudo ufw allow 443 # HTTPS
Managing UFW Rules
Check Firewall Status
Remove a Rule by Number
Reload UFW Rules
Enable UFW (If Not Enabled)
UFW Best Practices for Web Servers
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 80
sudo ufw allow 443
Then block SMTP outbound ports if email services are not required.
Thanks for visit my website
