Configure Linux Firewall: Step-by-Step

The steps to configure a Linux firewall are as follows:

  1. Check the firewall status by using the command sudo ufw status or sudo iptables -L.
  2. To enable or disable the firewall: use the command “sudo ufw enable” to turn on the firewall, and use the command “sudo ufw disable” to turn off the firewall.
  3. Set default policy: Use the command “sudo ufw default deny” to set the default policy as denying all inbound connections, or use the command “sudo ufw default allow” to set the default policy as allowing all inbound connections.
  4. Add rules to allow or deny: Use the command `sudo ufw allow ` to allow specific ports, for example `sudo ufw allow 80` allows HTTP traffic, and use the command `sudo ufw deny ` to deny specific ports.
  5. Rule deletion: Use the command “sudo ufw delete ” to remove a specific rule by its number, you can check the rule numbers by using “sudo ufw status numbered”.
  6. View logs: Use the command “sudo ufw logging on” to enable firewall logging, with log files stored by default in /var/log/ufw.log.
  7. Restart the firewall: use the command “sudo ufw reload” to reload the firewall rules.

Note: the above commands are mainly for managing firewalls using ufw (Uncomplicated Firewall). If using iptables to manage the firewall, the corresponding iptables commands should be used for configuration.

bannerAds