如何在不锁定自己的情况下将 Ubuntu 12.04 iptables 重置为默认值?

Hon*_*ger 35 iptables ubuntu-12.04

任何人都可以提供将 Ubuntu 12.04 的 iptables(防火墙)完全重置为其默认“工厂”设置的命令吗?据我所知,做错了会导致一个人被锁在 linux 盒子之外?

小智 45

将 iptables 的默认策略设置为 ACCEPT:

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
Run Code Online (Sandbox Code Playgroud)

然后刷新规则:

iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
Run Code Online (Sandbox Code Playgroud)

请注意,这不会影响备用表、NAT 表、PRE/POST 路由表等。


Ara*_*nda 25

这东西似乎没问题.. http://insanelabs.com/linux/linux-reset-iptables-firewall-rules/

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
Run Code Online (Sandbox Code Playgroud)

  • 伙计,你不知道我有多感激你的帖子!!!!经过几个小时的痛苦调试,我终于将 iptables 更改为默认值,现在我的问题已解决!我的问题是,我的 nodejs 服务器在 localhost:80 和 myip:80 上都运行良好,但我还有一台在 localhost:4000 上运行但在 myip:4000 上没有运行的 nodejs 服务器,我非常沮丧,因为这是在我的 raspberri pi 上安装邮件服务器之后发生的,而且是突然发生的。再一次,伙计,你有我的啤酒!谢谢! (2认同)

小智 6

当 出现问题时,Wing 的答案将助您一臂之力iptables。如果要重置所有内容,包括备用表NAT, PRE/POST ROUTING,请使用以下脚本:

#!/bin/sh
#
# rc.flush-iptables - Resets iptables to default values.
#
# Copyright (C) 2001 Oskar Andreasson <bluefluxATkoffeinDOTnet>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program or from the site that you downloaded it
# from; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Configurations
#
IPTABLES="/sbin/iptables"
#
# reset the default policies in the filter table.
#
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
#
# reset the default policies in the nat table.
#
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P POSTROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT
#
# reset the default policies in the mangle table.
#
$IPTABLES -t mangle -P PREROUTING ACCEPT
$IPTABLES -t mangle -P POSTROUTING ACCEPT
$IPTABLES -t mangle -P INPUT ACCEPT
$IPTABLES -t mangle -P OUTPUT ACCEPT
$IPTABLES -t mangle -P FORWARD ACCEPT
#
# flush all the rules in the filter and nat tables.
#
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
#
# erase all chains that's not default in filter and nat table.
#
$IPTABLES -X
$IPTABLES -t nat -X
$IPTABLES -t mangle -X
Run Code Online (Sandbox Code Playgroud)

来源:Internet 连接共享 - Ubuntu 帮助