How to configure firewall rules?

0151

Configuring firewall rules depends on the firewall software you are using. Below are examples for two common firewall management tools: iptables (Linux) and ufw (Uncomplicated Firewall, Ubuntu).

Using iptables

  1. View Current Rules:

    sudo iptables -L
  2. Allow Incoming Traffic on a Specific Port (e.g., port 80):

    sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  3. Deny Incoming Traffic on a Specific Port (e.g., port 22):

    sudo iptables -A INPUT -p tcp --dport 22 -j DROP
  4. Save the Rules (to persist after reboot):

    sudo iptables-save | sudo tee /etc/iptables/rules.v4
  5. Flush All Rules (if needed):

    sudo iptables -F

Using ufw

  1. Enable UFW (if not already enabled):

    sudo ufw enable
  2. Allow Incoming Traffic on a Specific Port (e.g., port 80):

    sudo ufw allow 80/tcp
  3. Deny Incoming Traffic on a Specific Port (e.g., port 22):

    sudo ufw deny 22/tcp
  4. Check Status and Rules:

    sudo ufw status
  5. Delete a Rule (if needed):

    sudo ufw delete allow 80/tcp

General Tips

  • Always review your firewall rules to ensure they meet your security requirements.
  • Test your configuration after making changes to ensure that the desired ports are open or closed as intended.
  • Consider logging dropped packets for troubleshooting purposes.

By following these steps, you can effectively configure firewall rules to manage network traffic on your system.

0 Comments

no data
Be the first to share your comment!