How do I temporarily (or permanently) flush / wipe my iptables?

I am having connection issues with my server, and I want to know if it is related to my service or my firewall. I would like to flush my iptables to either audit my rules or start from scratch. How can I go about this?

2 Replies

First you'll want to backup your iptables rules in case you want to reload them or edit them later. You can do so with the following commands:

sudo iptables-save > /root/firewall.rules
sudo ip6tables-save > /root/firewall6.rules

Then you can flush your firewall rules with the following commands:

sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT

Then you can check to see if you're still having an issue.

For reference if you need to restore the rules that we saved, you can do so with the following commands:

sudo iptables-restore < /root/firewall.rules
sudo ip6tables-restore < /root/firewall6.rules

If you are using UFW, you may reset your UFW rules using the following command:

sudo ufw reset

UFW will automatically back up your existing rules, but in case you would prefer to do so yourself, you may back up your existing rules set by copying the following files to a secure, off-site location:


Once you reset your UFW rules, UFW will disable itself. Before re-enabling UFW, I strongly advise allowing SSH connections:

sudo ufw allow ssh

If you are using a non-standard SSH port, you should specify so manually like this:

sudo ufw allow 23819/tcp

Be sure to replace 23819 with the actual TCP port number your SSH connection is using.

Once you re-allow your SSH connection through UFW, you should be able to safely re-enable UFW without locking yourself out of your Linode:

sudo ufw enable

You should now be enjoying a clean slate of UFW firewall rules which you may customize as you so please. For more information on UFW, you may consult this article from our Documentation:

How to Configure a Firewall with UFW

If you end up locking yourself out of your Linode, you may perform administrative tasks such as these from your Linode's Lish console using the information from this article:

Using the Linode Shell (Lish)


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct