web-dev-qa-db-ja.com

自分をロックアウトせずにUbuntu 12.04 iptablesをデフォルトにリセットする方法は?

Ubuntu 12.04のiptables(ファイアウォール)をデフォルトの「工場」設定に完全にリセットするコマンドを誰かが提供してくれませんか?私が理解していることから、これを間違って実行すると、Linuxボックスからロックアウトされますか?

28
Honey Badger

IptablesのデフォルトポリシーをACCEPTに設定します。

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

次に、ルールをフラッシュします。

iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD

これは、代替テーブル、NATテーブル、PRE/POSTルーティングテーブルなど)には影響しません。

38
Wing Tang Wong

これは問題ないようです。 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
16
Aravinda

ウィングの答え は、iptablesで問題が発生したときにあなたの助けになります。代替テーブルを含むすべてをリセットする場合は、NATPRE/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

ソース: インターネット接続の共有-Ubuntuヘルプ

3
Sahil Arora