How to open the firewall in Linux?

In Linux, you can enable the firewall using the iptables command. Below are the steps to activate the firewall using the iptables command.

  1. Log in to the Linux system with root privileges.
  2. Open the terminal.
  3. Enter the following command to view the current firewall rules:
  4. List all current firewall rules.
  5. If there are currently no rules, the firewall is off. If there are rules, you can choose to clear them.
  6. Clear all rules in iptables.
  7. Use the following command to allow all incoming and outgoing connections:
  8. – Change the default input policy to accept
    – Change the default output policy to accept
  9. Enter the following command to enable local loopback connection:
  10. Allow all traffic on the “lo” interface for both incoming and outgoing traffic.
  11. Enter the following command to allow established connections:
  12. Allow all incoming and outgoing connections that are established or related using conntrack.
  13. Use the following command to save the modified rules:
  14. Save the current iptables configuration to the file /etc/iptables/rules.v4.
  15. Enter the command to start the firewall:
  16. Please initiate iptables using systemctl.

The firewall is currently activated and allows all incoming and outgoing connections. You can customize more rules as needed.

bannerAds