Enabling UFW and Setting Up Firewall Rules
Enable UFW:
To enable UFW, use the following command:
sudo ufw enableAfter running this command, UFW will be active, and the default policy will be to deny all incoming connections.
Allow Specific Services or Ports:
You can allow specific services or ports by using UFW. For example, to allow incoming SSH connections (port 22), you can use the following command:
sudo ufw allow sshIf you want to allow other services, replace
sshwith the service name (e.g.,http,https,ftp, etc.) or the port number you want to allow.Check UFW Status:
After setting up your rules, you can check the status to ensure everything is configured correctly:
sudo ufw statusIt should display your active rules.
Configure Outbound Connections (Optional):
UFW by default allows all outbound connections. If you want to restrict outbound connections, you can set specific rules for outbound traffic. For example, to deny outgoing connections on port 80 (HTTP), you can use:
sudo ufw deny out 80Replace
80with the port number you want to restrict.Other Useful Commands:
To delete a rule:
sudo ufw delete <rule>To disable UFW:
sudo ufw disable