From cf8db8955fbcea0dcebbdc011f2f2c7802d4c5a9 Mon Sep 17 00:00:00 2001 From: darksun Date: Thu, 21 Jun 2018 16:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E9=A2=98:=20How=20to=20disable=20ipta?= =?UTF-8?q?bles=20firewall=20temporarily?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...o disable iptables firewall temporarily.md | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 sources/tech/20180619 How to disable iptables firewall temporarily.md diff --git a/sources/tech/20180619 How to disable iptables firewall temporarily.md b/sources/tech/20180619 How to disable iptables firewall temporarily.md new file mode 100644 index 0000000000..1095f13495 --- /dev/null +++ b/sources/tech/20180619 How to disable iptables firewall temporarily.md @@ -0,0 +1,104 @@ +How to disable iptables firewall temporarily +====== + +Learn how to disable iptables firewall in Linux temporarily for troubleshooting purpose. Also learn how to save policies and how to restore them back when you enable firewall back. + +![How to disable iptables firewall temporarily][1] + +Sometimes you have the requirement to turn off iptables firewall to do some connectivity troubleshooting and then you need to turn it back on. While doing it you also want to save all your [firewall policies][2] as well. In this article, we will walk you through how to save firewall policies and how to disable/enable iptables firewall. For more details about iptables firewall and policies [read our article][3] on it. + +### Save iptables policies + +The first step while disabling iptables firewall temporarily is to save existing firewall rules/policies. `iptables-save` command lists all your existing policies which you can save in a file on your server. + +``` +root@kerneltalks # # iptables-save +# Generated by iptables-save v1.4.21 on Tue Jun 19 09:54:36 2018 +*nat +:PREROUTING ACCEPT [1:52] +:INPUT ACCEPT [1:52] +:OUTPUT ACCEPT [15:1140] +:POSTROUTING ACCEPT [15:1140] +:DOCKER - [0:0] +---- output trucated---- + +root@kerneltalks # iptables-save > /root/firewall_rules.backup +``` + +So iptables-save is the command with you can take iptables policy backup. + +### Stop/disable iptables firewall + +For older Linux kernels you have an option of stopping service iptables with `service iptables stop` but if you are on the new kernel, you just need to wipe out all the policies and allow all traffic through the firewall. This is as good as you are stopping the firewall. + +Use below list of commands to do that. +``` +root@kerneltalks # iptables -F +root@kerneltalks # iptables -X +root@kerneltalks # iptables -P INPUT ACCEPT +root@kerneltalks # iptables -P OUTPUT ACCEPT +root@kerneltalks # iptables -P FORWARD ACCEPT +``` + +Where – + + * -F : Flush all policy chains + * -X : Delete user defined chains + * -P INPUT/OUTPUT/FORWARD : Accept specified traffic + + + +Once done, check current firewall policies. It should looks like below which means everything is accepted (as good as your firewall is disabled/stopped) + +``` +# iptables -L +Chain INPUT (policy ACCEPT) +target prot opt source destination + +Chain FORWARD (policy ACCEPT) +target prot opt source destination + +Chain OUTPUT (policy ACCEPT) +target prot opt source destination +``` + +### Restore firewall policies + +Once you are done with troubleshooting and you want to turn iptables back on with all its configurations. You need to first restore policies from the backup we took in first step. + +``` +root@kerneltalks # iptables-restore