How to configure firewall rules in Ubuntu?
In Ubuntu, you can use ufw (Uncomplicated Firewall) to set firewall rules. Here are some common tasks:
- Uncomplicated Firewall
sudo apt update
sudo apt install ufw
- uncomplicated firewall
sudo ufw enable
- Allow or deny access to specific ports.
sudo ufw allow <port_number>/tcp
sudo ufw deny <port_number>/tcp
- Allowing or denying access to specific IP addresses:
sudo ufw allow from <ip_address>
sudo ufw deny from <ip_address>
- Grant or deny access to specific subnets:
sudo ufw allow from <subnet>
sudo ufw deny from <subnet>
- View the current firewall rules.
sudo ufw status
- Disable specific rules:
sudo ufw delete <rule_number>
Please ensure that when setting up firewall rules, you do not block yourself from accessing the server or other necessary services. Remember to re-enable the firewall after modifying the rules to make the changes take effect.