Step-by-Step Guide: Accessing and Managing Firewall on a Linux VPS using ufw
To access the firewall on your Linux VPS, you can use "iptables" or the more user-friendly frontend "ufw" (Uncomplicated Firewall). Here's a step-by-step guide to managing the firewall with ufw:
- Connect to Your Linux VPS:
- Use SSH or any other remote access method to connect to your Linux VPS.
- Log In to Your VPS:
- Open a terminal or SSH client and log in to your VPS using your credentials.
- Check for ufw Installation:
- To check if ufw is installed, run the command:
sudo ufw status
- If ufw is not installed, you can install it with:
sudo apt update
sudo apt install ufw
- Enable ufw:
- Once ufw is installed, enable it with:
sudo ufw enable
- Note: Enabling ufw may briefly drop your SSH connection. Ensure you have alternative access to your VPS in case of disconnection.
- Allow Incoming Connections to Specific Ports:
- To permit incoming connections to a specific port, use:
sudo ufw allow <port_number>
- Replace
<port_number>
with the desired port (e.g., 80 for HTTP). - To specify a protocol (e.g., TCP or UDP), add it after the port number:
sudo ufw allow 22/tcp
- Deny Incoming Connections on Specific Ports:
- To deny incoming connections on a specific port, use:
sudo ufw deny <port_number>
- Check ufw Status and Firewall Rules:
- View the current firewall rules and ufw status with:
sudo ufw status verbose
- Modify or Delete Existing Rules:
- You can modify or delete existing rules using ufw commands. Consult the ufw documentation or run
man ufw
for advanced configuration options.
Remember to be cautious when configuring the firewall to avoid unintended blocking of necessary connections or exposing your VPS to security risks. Review and test your firewall rules thoroughly for best practices.