Why use a firewall?
A firewall decides which network connections can reach your server. Closing every port you do not use removes a large part of the risk of attack.
Before you start
- Log in to your VPS over SSH.
- Use a user with sudo rights.
- Make sure you allow SSH before enabling the firewall, or you will lock yourself out.
Step 1: Allow the ports you need
sudo ufw allow OpenSSH
sudo ufw allow 80
sudo ufw allow 443
Port 80 is HTTP and 443 is HTTPS. Only open other ports if you really need them.
Step 2: Turn the firewall on
sudo ufw enable
Confirm with y when asked.
Step 3: Check the rules
sudo ufw status verbose
Common tasks
- Block a port: sudo ufw deny 3306
- Delete a rule: sudo ufw delete allow 80
- Allow SSH only from your IP: sudo ufw allow from YOUR_IP to any port 22
Tips
- Keep database ports such as 3306 closed to the internet unless you have a specific reason.
- If you lock yourself out, use the console in your VPS control panel to fix the rules.
Need help?
If you get stuck, open a support ticket or email info@webzworld.com and our team will help.