| ライター翻訳版 - March 29, 2006 |
| 機械翻訳版 - September 30, 2008 |
| 英語版 - September 30, 2008 |
| Document ID: 6209 |
目次
概要
前提条件
要件
使用するコンポーネント
表記法
NAT の概要
NAT の設定と出力
関連情報
概要
このドキュメントは、Network Address Translation(NAT; ネットワーク アドレス変換)を使用したトランザクションの処理順序について説明しています。この処理順序はパケットの流れる方向(内部ネットワークから外部ネットワーク、または外部ネットワークから内部ネットワーク)によって決まります。
前提条件
要件
このドキュメントの読者は、次の事項に関する知識が必要です。
-
Network Address Translation(NAT; ネットワーク アドレス変換)。 NAT の詳細については、『NAT の動作の仕組み』を参照してください。
使用するコンポーネント
このドキュメントは特定のソフトウェアやハードウェアのバージョンに限定されるものではありません。
注:このドキュメントに記載されている情報は、Cisco IOS(R) ソフトウェア リリース 12.2(27) に基づくものです。
表記法
ドキュメント表記の詳細は、『シスコ テクニカル ティップスの表記法』を参照してください。
NAT の概要
次の表からわかるように、グローバルからローカルへの NAT 変換、またはローカルからグローバルへの NAT 変換がいつ実行されるかは、それぞれのフローによって異なります。
| 内部から外部へ | 外部から内部へ |
|---|---|
|
|
NAT の設定と出力
次の例は、動作の順序が NAT に与える影響について示しています。このケースでは、NAT とルーティングだけを示しています。

上の例では、次の設定に示すように、ルータ A は内部ローカル アドレス 171.68.200.48 を 172.16.47.150 に変換するように設定されています。
! version 11.2 no service udp-small-servers no service tcp-small-servers ! hostname Router-A ! enable password ww ! ip nat inside source static 171.68.200.48 172.16.47.150 !--- このコマンドは、171.68.200.48 と 172.16.47.150 との間の !--- スタティックな NAT 変換を作成します。 ip domain-name cisco.com ip name-server 171.69.2.132 ! interface Ethernet0 no ip address shutdown ! interface Serial0 ip address 172.16.47.161 255.255.255.240 ip nat inside !--- Serial0 を NAT の内側のインターフェイスとして設定します。 no ip mroute-cache no ip route-cache no fair-queue ! interface Serial1 ip address 172.16.47.146 255.255.255.240 ip nat outside !--- Serial1 を NAT の外側のインターフェイスとして設定します。 no ip mroute-cache no ip route-cache ! no ip classless ip route 0.0.0.0 0.0.0.0 172.16.47.145 !--- デフォルト ルートを 172.16.47.145 に設定します。 ip route 171.68.200.0 255.255.255.0 172.16.47.162 ! ! line con 0 exec-timeout 0 0 line aux 0 line vty 0 4 password ww login ! end
変換テーブルでは、意図した変換が存在することが示されています。
Router-A#show ip nat translation Pro Inside global Inside local Outside local Outside global --- 172.16.47.150 171.68.200.48 --- ---
次の出力は、Router A から得られたものです。Router A では debug ip packet detail および debug ip nat が有効にされています。ここでは、デバイス 171.68.200.48 から 172.16.47.142 宛てに ping が実行されています。
注:デバッグ コマンドでは、かなりの量の出力が生成されます。 これらのコマンドは IP ネットワーク上のトラフィックが少ないときだけ使用し、システム上の他のアクティビティが悪影響を受けないようにしてください。 debug コマンドを発行する前に、『デバッグ コマンドの重要な情報』を参照してください。
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
ICMP type=8, code=0
IP: s=172.16.47.161 (local), d=171.68.200.48 (Serial0), len 56, sending
ICMP type=3, code=1
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
ICMP type=8, code=0
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
ICMP type=8, code=0
IP: s=172.16.47.161 (local), d=171.68.200.48 (Serial0), len 56, sending
ICMP type=3, code=1
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
ICMP type=8, code=0
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
ICMP type=8, code=0
IP: s=172.16.47.161 (local), d=171.68.200.48 (Serial0), len 56, sending
ICMP type=3, code=1
上の出力には NAT のデバッグ メッセージが見られないため、既存のスタティック トランスレーションが使用されていないことと、ルータが宛先アドレス(172.16.47.142)へのルートを自身のルーティング テーブルに持っていないことがわかります。 パケットがルーティングできないため、ICMP 到達不能メッセージが生成され、内部デバイスに送信されます。
しかし、Router A には 172.16.47.145 のデフォルト ルートがあります。では、なぜルートがルーティング不能と見なされるのでしょうか。
Router A では no ip classless が設定されています。これは、パケットの宛先が「メジャー」ネットワーク アドレスの場合(この場合は 172.16.0.0)、そのサブネットがルーティング テーブルに存在すると、ルータはデフォルト ルートに依存しないことを意味しています。 つまり、no ip classless コマンドを発行すると、最長一致(ビット)法でルートを探すというルータの機能がオフになってしまいます。 この動作を変更するには、Router A で ip classless を設定する必要があります。ip classless コマンドは、IOS バージョン 11.3 以降が稼働しているシスコ ルータではデフォルトでイネーブルになっています。
Router-A#configure terminal Enter configuration commands, one per line. End with CTRL/Z. Router-A(config)#ip classless Router-A(config)#end
Router-A#show ip nat translation %SYS-5-CONFIG_I: Configured from console by console nat tr Pro Inside global Inside local Outside local Outside global --- 172.16.47.150 171.68.200.48 --- ---
先ほどと同じ ping テストを再び実行すると、パケットが変換されて ping が成功することがわかります。
Ping Response on device 171.68.200.48
D:\>ping 172.16.47.142 Pinging 172.16.47.142 with 32 bytes of data:
Reply from 172.16.47.142: bytes=32 time=10ms TTL=255 Reply from 172.16.47.142: bytes=32 time<10ms TTL=255 Reply from 172.16.47.142: bytes=32 time<10ms TTL=255 Reply from 172.16.47.142: bytes=32 time<10ms TTL=255
Ping statistics for 172.16.47.142: Packets: Sent = 4, Received = 4, Lost = 0 (0%) Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 10ms, Average = 2ms
Debug messages on Router A indicating that the packets generated by device 171.68.200.48 are getting translated by NAT.
Router-A# *Mar 28 03:34:28: IP: tableid=0, s=171.68.200.48 (Serial0), d=172.16.47.142 (Serial1), routed via RIB *Mar 28 03:34:28: NAT: s=171.68.200.48->172.16.47.150, d=172.16.47.142 [160] *Mar 28 03:34:28: IP: s=172.16.47.150 (Serial0), d=172.16.47.142 (Serial1), g=172.16.47.145, len 100, forward *Mar 28 03:34:28: ICMP type=8, code=0 *Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150->171.68.200.48 [160] *Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), routed via RIB *Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), g=172.16.47.162, len 100, forward *Mar 28 03:34:28: ICMP type=0, code=0 *Mar 28 03:34:28: NAT*: s=171.68.200.48->172.16.47.150, d=172.16.47.142 [161] *Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150->171.68.200.48 [161] *Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), routed via RIB *Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), g=172.16.47.162, len 100, forward *Mar 28 03:34:28: ICMP type=0, code=0 *Mar 28 03:34:28: NAT*: s=171.68.200.48->172.16.47.150, d=172.16.47.142 [162] *Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150->171.68.200.48 [162] *Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), routed via RIB *Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), g=172.16.47.162, len 100, forward *Mar 28 03:34:28: ICMP type=0, code=0 *Mar 28 03:34:28: NAT*: s=171.68.200.48->172.16.47.150, d=172.16.47.142 [163] *Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150->171.68.200.48 [163] *Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), routed via RIB *Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), g=172.16.47.162, len 100, forward *Mar 28 03:34:28: ICMP type=0, code=0 *Mar 28 03:34:28: NAT*: s=171.68.200.48->172.16.47.150, d=172.16.47.142 [164] *Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150->171.68.200.48 [164] *Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), routed via RIB *Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), g=172.16.47.162, len 100, forward *Mar 28 03:34:28: ICMP type=0, code=0
Router-A#undebug all All possible debugging has been turned off
上の例は、パケットが内部から外部に向けて送られるとき、NAT ルータは外部アドレスへのルートがないか自身のルーティング テーブルをチェックし、それからパケットの変換を続けることを示しています。 したがって、NAT ルータが外部ネットワークへの有効なルートを持っていることが重要になります。 宛先ネットワークへのルートは、ルータの設定の中で NAT outside として定義されているインターフェイスを通じて学習している必要があります。
戻りパケットはルーティングされる前に変換されることに注意してください。 したがって、NAT ルータは内部ローカル アドレスへの有効なルートも、自身のルーティング テーブルに持っている必要があります。
