To delete all rules from the iptables, you can use the following commands. Note that you will need administrative privileges to execute these commands.
Flush all rules in all chains: This will remove all rules in the filter, nat, mangle, and raw tables.
sudo iptables -F # Flush all the rules from the filter table
sudo iptables -X # Delete all user-defined chains in the filter table
sudo iptables -t nat -F # Flush all rules in the nat table
sudo iptables -t nat -X # Delete all user-defined chains in the nat table
sudo iptables -t mangle -F # Flush all rules in the mangle table
sudo iptables -t mangle -X # Delete all user-defined chains in the mangle table
sudo iptables -t raw -F # Flush all rules in the raw table
sudo iptables -t raw -X # Delete all user-defined chains in the raw table
User
https open port iptables
Assistant
To open the HTTPS port (port 443) in iptables, you will need to allow incoming traffic on this port. Here are the commands you can use to achieve this:
Reset default policies: After flushing the rules, you should also reset the default policies for the built-in chains to ACCEPT, if you want to allow all traffic:
Save the changes (if needed): Depending on the Linux distribution, you might want to save the changes so that they persist across reboots. This can vary—is not usually handled by iptables itself—but rather by configuration utilities like iptables-save or your distribution's specific instructions (e.g., iptables-persistent for Debian/Ubuntu).
sudo iptables-save > /etc/iptables/rules.v4 # For IPv4
sudo iptables-save > /etc/iptables/rules.v6 # For IPv6 if needed.
These commands will effectively clear all the existing rules in your iptables configuration. Be cautious when doing this, especially on servers, as it can expose your machine to unwanted access if not properly configured afterward.
Allow HTTPS traffic on port 443:
For IPv4:
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
For IPv6, if you are using ip6tables:
sudo ip6tables -A INPUT -p tcp --dport 443 -j ACCEPT
Ensure that you have a policy that allows established and related connections: It's common practice to allow established connections before adding new rules. If you haven't done this yet, you can use the following command:
For IPv4:
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
For IPv6:
sudo ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
Set the default policy if necessary: If your default policy on the INPUT chain is set to DROP, ensure you also have a rule allowing traffic from localhost (if not already set):
For IPv4:
sudo iptables -A INPUT -i lo -j ACCEPT
For IPv6:
sudo ip6tables -A INPUT -i lo -j ACCEPT
Save the changes (if needed): Depending on your Linux distribution, you might want to save these changes. Use iptables-save to ensure the rules are preserved across reboots:
sudo iptables-save > /etc/iptables/rules.v4 # For IPv4
sudo ip6tables-save > /etc/iptables/rules.v6 # For IPv6, if applicable.
Full Example
Here is a complete example, which assumes you haven't previously set any iptables rules:
# Allow loopback
sudo iptables -A INPUT -i lo -j ACCEPT
# Allow established connections
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Open HTTPS (port 443)
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Set default policy to drop (optional; be careful with existing rules!)
sudo iptables -P INPUT DROP
# Save the changes
sudo iptables-save > /etc/iptables/rules.v4
Important Notes:
Be cautious when changing firewall rules, particularly on remote systems. If misconfigured, you may lock yourself out.
Always ensure that you have rules allowing SSH (port 22, or any specific port you use for remote access) before setting a default DROP policy, to avoid losing remote access.
It’s important to understand your network and security requirements before configuring your firewall rules.