「iptables」の版間の差分

提供: セキュリティ
移動: 案内検索
 
(同じ利用者による、間の9版が非表示)
行1: 行1:
<!--
+
[[iptables]]  は、[[Linux]] に実装された[[IPv4]]用のパケットフィルタリングやネットワーク変換機能、または、コマンドのことです。
vim: filetype=mediawiki
+
[[IPv6]] 用には、 ip6tables があります。
-->
+
[[{{PAGENAME}}]]  は、[[Linux]] に実装された[[IPv4]]用の[[パケットフィルタリング]]やネットワーク変換機能、または、コマンドのことです。
+
[[IPv6]] 用には、 [[ip6tables]] があります。
+
  
読み方
+
'''読み方'''
;[[{{PAGENAME}}]]:
+
;[[iptables]]: あいぴー てーぶるす
 
__TOC__
 
__TOC__
  
 
== 概要 ==
 
== 概要 ==
 +
[[iptables]] は、[[Linux]] の [[ファイアーウォール]]として利用できます。
 +
[[iptables]]は、大きく分類してパケットフィルタリングとNAT(Network Address Translation)の機能を提供します。
 +
;パケットフィルタリング: [[ファイアーウォール]]の機能で、IP[[パケット]]の送信、受信、転送の許可条件を設定します。
 +
;NAT:ルータとして[[Linux]]を使用する場合に利用し、[[パケット]]の転送時に送信元、宛先IPアドレスをに変換します。
  
[[{{PAGENAME}}]] は、[[Linux]] の [[ファイアーウォール]]として利用できます。
+
NATには、以下の種類があります。
 
+
* Destination NAT(DNAT)
* [[iptables のインストール]]
+
* Srouce NAT(SNAT)
* [[iptables のテーブル]]
+
* IPマスカレード
* [[iptables のサービスのコントロール]]
+
== iptables ==
* [[iptables のコマンドラインオプション]]
+
{{iptables}}
* [[iptables のルールを確認する]]
+
* [[iptables の設定の変更]]
+
** [[iptables-save]]
+
** [[iptables-restore]]
+
** [[iptables の設定をクリアする]]
+
** [[iptables の設定を削除する]]
+
* [[iptables のターゲット]]
+
* [[iptables ログを出力する]]
+
* [[iptables アクセス回数を制限する]]
+
* [[iptables 接続状態]]
+
* [[iptables が動かない場合]]
+
 
+
* [[iptables icmp echo requestを許可する]]
+
* [[iptables DNSを許可する]]
+
* [[iptables HTTPとHTTPSを許可する]]
+
 
+
== 設定ファイル ==
+
 
+
[[iptables]] の設定ファイルは、下記の場所にあります。
+
/etc/sysconfig/iptables-config
+
/etc/sysconfig/iptables
+
 
+
 
+
 
== 使い方 ==
 
== 使い方 ==
 
 
 
=== iptables の設定 ===
 
=== iptables の設定 ===
 
 
/etc/sysconfig/iptables の設定例。
 
/etc/sysconfig/iptables の設定例。
  
行78: 行53:
 
COMMIT
 
COMMIT
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
 
=== iptables の設定と起動 ===
 
=== iptables の設定と起動 ===
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% sudo cp ./iptables /etc/sysconfig/iptables
 
% sudo cp ./iptables /etc/sysconfig/iptables
行87: 行59:
 
iptables: Applying firewall rules:                        [  OK  ]
 
iptables: Applying firewall rules:                        [  OK  ]
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== HTTPとHTTPSを許可する ===
 
 
[[HTTP]] (80)と [[HTTPS]]  (443) を許可する例です。
 
 
<syntaxhighlight lang="bash">
 
-A INPUT -p tcp --dport 80 -j ACCEPT
 
-A INPUT -p tcp --dport 443 -j ACCEPT
 
</syntaxhighlight>
 
 
<syntaxhighlight lang="bash">
 
*filter
 
:INPUT DROP [0:0]
 
:FORWARD DROP [0:0]
 
:OUTPUT ACCEPT [0:0]
 
-A INPUT -i lo -j ACCEPT
 
-A INPUT -p tcp --dport 22 -j ACCEPT
 
-A INPUT -p tcp --dport 80 -j ACCEPT
 
-A INPUT -p tcp --dport 443 -j ACCEPT
 
-A OUTPUT -o lo -j ACCEPT
 
COMMIT
 
</syntaxhighlight>
 
 
 
 
=== icmp echo requestを許可する ===
 
 
<syntaxhighlight lang="bash">
 
-A INPUT -p icmp --icmp-type echo-request -j ACCEPT
 
</syntaxhighlight>
 
 
 
 
== iptables の設定の保存と復元 ==
 
== iptables の設定の保存と復元 ==
 
 
[[iptables-save]] コマンドでは、[[iptables]]の設定を標準出力に出します。
 
[[iptables-save]] コマンドでは、[[iptables]]の設定を標準出力に出します。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
行142: 行81:
 
# Completed on Sat Apr 27 15:26:09 2013
 
# Completed on Sat Apr 27 15:26:09 2013
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== iptables の設定を保存する ==
 
== iptables の設定を保存する ==
 
 
[[iptables]] コマンドで設定した情報は、 save を実行しないと保存されません。
 
[[iptables]] コマンドで設定した情報は、 save を実行しないと保存されません。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% sudo service iptables save
 
% sudo service iptables save
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== 関連項目 ==
 
== 関連項目 ==
 
+
{{iptables}}
 +
* [[ufw]]
 
* [[ファイアーウォール]]
 
* [[ファイアーウォール]]
* [[lokkit]]
+
* lokkit
 +
* http://www.netfilter.org/
 +
<!-- vim: filetype=mediawiki
 +
-->

2016年1月11日 (月) 21:40時点における最新版

iptables は、Linux に実装されたIPv4用のパケットフィルタリングやネットワーク変換機能、または、コマンドのことです。 IPv6 用には、 ip6tables があります。

読み方

iptables
あいぴー てーぶるす

概要

iptables は、Linuxファイアーウォールとして利用できます。 iptablesは、大きく分類してパケットフィルタリングとNAT(Network Address Translation)の機能を提供します。

パケットフィルタリング
ファイアーウォールの機能で、IPパケットの送信、受信、転送の許可条件を設定します。
NAT
ルータとしてLinuxを使用する場合に利用し、パケットの転送時に送信元、宛先IPアドレスをに変換します。

NATには、以下の種類があります。

  • Destination NAT(DNAT)
  • Srouce NAT(SNAT)
  • IPマスカレード

iptables

使い方

iptables の設定

/etc/sysconfig/iptables の設定例。

  • プライベートアドレスからの ssh のアクセスを許可する
  • ローカルホストからのアクセスを許可する
  • それ以外は、許可しない
# Generated by iptables-save v1.4.7 on Sat Apr 27 15:31:38 2013
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -s 192.168.0.0/24 -p tcp --dport 22 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
COMMIT
# Completed on Sat Apr 27 15:31:38 2013


  • どこからでも ssh のアクセスを許可する
  • ローカルホストからのアクセスを許可する
  • それ以外は、許可しない
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp --dport 22 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
COMMIT

iptables の設定と起動

% sudo cp ./iptables /etc/sysconfig/iptables
% sudo service iptables start
iptables: Applying firewall rules:                         [  OK  ]

iptables の設定の保存と復元

iptables-save コマンドでは、iptablesの設定を標準出力に出します。

iptables-save > iptables.save

iptables-restore は、iptables の設定を読み込み、iptables に反映します。

iptables-restore < iptables.save

iptables-save の実行例。

% iptables-save
# Generated by iptables-save v1.4.7 on Sat Apr 27 15:26:09 2013
*filter
:INPUT ACCEPT [79:6000]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [66:7992]
COMMIT
# Completed on Sat Apr 27 15:26:09 2013

iptables の設定を保存する

iptables コマンドで設定した情報は、 save を実行しないと保存されません。

% sudo service iptables save

関連項目