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.
- Log in to the Linux system with root privileges.
- Open the terminal.
- Enter the following command to view the current firewall rules:
- List all current firewall rules.
- If there are currently no rules, the firewall is off. If there are rules, you can choose to clear them.
- Clear all rules in iptables.
- Use the following command to allow all incoming and outgoing connections:
- – Change the default input policy to accept
– Change the default output policy to accept - Enter the following command to enable local loopback connection:
- Allow all traffic on the “lo” interface for both incoming and outgoing traffic.
- Enter the following command to allow established connections:
- Allow all incoming and outgoing connections that are established or related using conntrack.
- Use the following command to save the modified rules:
- Save the current iptables configuration to the file /etc/iptables/rules.v4.
- Enter the command to start the firewall:
- Please initiate iptables using systemctl.
The firewall is currently activated and allows all incoming and outgoing connections. You can customize more rules as needed.