Setting up a firewall with UFW (Uncomplicated Firewall) on Ubuntu 22.04 is a straightforward process. UFW is a user-friendly interface for managing iptables, the default firewall management tool on Linux. Here's a step-by-step guide:
Step 1 : Install UFW, If UFW is not installed on your system, you can install it by running:
Step 2 : Check UFW Status : Before enabling the firewall, it's a good idea to check the status of UFW to ensure it's inactive:
Step 3 : Allow SSH Access : If you are connected to your server via SSH, make sure to allow SSH traffic to avoid getting locked out:
Replace "ssh" with the port number if you are using a custom SSH port.
Step 4 : Allow Other Necessary Services
Allow other services that your server needs. For example, if you are running a web server, you might need to allow HTTP (port 80) and HTTPS (port 443):
Step 5 : Enable UFW
You will be prompted to confirm the action. Type "y" and press Enter.
Step 6 : Check UFW Status Again
Verify the status of UFW to ensure that it is active and that the rules are applied:
Step 7 : Additional Configuration (Optional)
You can further customize your firewall rules based on your specific needs. For example, you might want to allow or deny traffic on specific ports.
Step 8 : Disable UFW (if needed)
If you ever need to disable UFW temporarily, you can do so with the following command:
Remember to re-enable it when you are done:
That's it! You've successfully set up a basic firewall using UFW on Ubuntu 22.04. Adjust the rules according to your specific requirements.