How to configure firewall rules in Ubuntu?

In Ubuntu, you can use ufw (Uncomplicated Firewall) to set firewall rules. Here are some common tasks:

  1. Uncomplicated Firewall
sudo apt update
sudo apt install ufw
  1. uncomplicated firewall
sudo ufw enable
  1. Allow or deny access to specific ports.
sudo ufw allow <port_number>/tcp
sudo ufw deny <port_number>/tcp
  1. Allowing or denying access to specific IP addresses:
sudo ufw allow from <ip_address>
sudo ufw deny from <ip_address>
  1. Grant or deny access to specific subnets:
sudo ufw allow from <subnet>
sudo ufw deny from <subnet>
  1. View the current firewall rules.
sudo ufw status
  1. 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.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds