mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
选题: How to disable iptables firewall temporarily
This commit is contained in:
parent
5fca0b4fce
commit
cf8db8955f
@ -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 </root/firewall_rules.backup
|
||||||
|
```
|
||||||
|
### Start iptables firewall
|
||||||
|
|
||||||
|
And then start iptables service in case you have stopped it in previous step using `service iptables start`. If you havnt stopped service then only restoring policies will do for you. Check if all policies are back in iptables firewall configurations :
|
||||||
|
|
||||||
|
```
|
||||||
|
# iptables -L
|
||||||
|
Chain INPUT (policy ACCEPT)
|
||||||
|
target prot opt source destination
|
||||||
|
|
||||||
|
Chain FORWARD (policy DROP)
|
||||||
|
target prot opt source destination
|
||||||
|
DOCKER-USER all -- anywhere anywhere
|
||||||
|
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
|
||||||
|
-----output truncated-----
|
||||||
|
```
|
||||||
|
|
||||||
|
That’s it! You have successfully disabled and enabled firewall without loosing your policy rules.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://kerneltalks.com/howto/how-to-disable-iptables-firewall-temporarily/
|
||||||
|
|
||||||
|
作者:[kerneltalks][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]:https://kerneltalks.com
|
||||||
|
[1]:https://a2.kerneltalks.com/wp-content/uploads/2018/06/How-to-disable-iptables-firewall-temporarily.png
|
||||||
|
[2]:https://kerneltalks.com/networking/configuration-of-iptables-policies/
|
||||||
|
[3]:https://kerneltalks.com/networking/basics-of-iptables-linux-firewall/
|
Loading…
Reference in New Issue
Block a user