snipt

Ctrl+h for KB shortcuts

Bash

Completely flush iptables

1
2
3
4
5
6
7
8
# Source: https://serverfault.com/a/200642/88004

iptables-save | awk '/^[*]/ { print $1 } 
                     /^:[A-Z]+ [^-]/ { print $1 " ACCEPT" ; }
                     /COMMIT/ { print $0; }' | iptables-restore

# "All policies will be reset to ACCEPT as well as flushing every table in current use.
#     All chains other than the built in chains will no longer exist."
https://snipt.net/embed/4255fdb928925407842a67e46c64fc17/
/raw/4255fdb928925407842a67e46c64fc17/
4255fdb928925407842a67e46c64fc17
bash
Bash
8
2019-06-18T05:38:31
True
False
False
/api/public/snipt/147274/
completely-flush-iptables
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Source: https://serverfault.com/a/200642/88004</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>iptables-save <span class="p">|</span> awk <span class="s1">&#39;/^[*]/ { print $1 } </span> </span><span id="L-4"><a name="L-4"></a><span class="s1"> /^:[A-Z]+ [^-]/ { print $1 &quot; ACCEPT&quot; ; }</span> </span><span id="L-5"><a name="L-5"></a><span class="s1"> /COMMIT/ { print $0; }&#39;</span> <span class="p">|</span> iptables-restore </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="c1"># &quot;All policies will be reset to ACCEPT as well as flushing every table in current use.</span> </span><span id="L-8"><a name="L-8"></a><span class="c1"># All chains other than the built in chains will no longer exist.&quot;</span> </span></pre></div> </td></tr></table>
iptables
--- 
+++ 
@@ -2,4 +2,7 @@
 
 iptables-save | awk '/^[*]/ { print $1 } 
                      /^:[A-Z]+ [^-]/ { print $1 " ACCEPT" ; }
-                     /COMMIT/ { print $0; }' | iptables-restore+                     /COMMIT/ { print $0; }' | iptables-restore
+
+# "All policies will be reset to ACCEPT as well as flushing every table in current use.
+#     All chains other than the built in chains will no longer exist."
  • boweeb
  • 2 years, 7 months ago
1
2
3
4
5
6
7
8
--- 
+++ 
@@ -0,0 +1,5 @@
+# Source: https://serverfault.com/a/200642/88004
+
+iptables-save | awk '/^[*]/ { print $1 } 
+                     /^:[A-Z]+ [^-]/ { print $1 " ACCEPT" ; }
+                     /COMMIT/ { print $0; }' | iptables-restore
  • boweeb
  • 2 years, 12 months ago