簡介
本文檔介紹如何配置和驗證網路地址轉換(NAT)和兩次NAT。
必要條件
需求
思科建議您瞭解以下主題:
採用元件
名稱 |
平台 |
版本 |
N9K1 |
N9K-C93108TC-EX |
9.3(10) |
N9K2 |
N9K-C93108TC-EX |
9.3(10) |
N9K3 |
N9K-C93108TC-EX
|
9.3(10)
|
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
網路圖表
配置轉換全局內部IP
內部全局IP:10.1.1.1
內部本地IP:192.168.1.1
N9K1 |
N9K2 |
N9K3 |
interface Ethernet1/1
ip address 10.10.10.10/24
no shut
interface loopback 0
ip address 10.1.1.1/32
ip route 0.0.0.0/0 10.10.10.1
|
feature nat
ip access-list tac-nat-inside
permit ip host 10.1.1.1 any
ip nat pool tac-nat-inside-pool 192.168.1.1 192.168.1.1 prefix-length 32
ip nat inside source list tac-nat-inside pool tac-nat-inside-pool dynamic add-route
interface Ethernet1/1
ip nat inside
ip address 10.10.10.11/24
no shut
interface Ethernet1/2
ip nat outside
ip address 10.20.20.21/24
no shut
ip route 10.3.3.3/32 10.20.20.20
ip route 10.1.1.1/32 10.10.10.10
|
interface Ethernet1/2
ip address 10.20.20.20/24
no shut
interface loopback 0
ip address 10.3.3.3/32
ip route 0.0.0.0/0 10.20.20.21
|
注意:由於IP 192.168.1.1不存在於任何裝置上,因此nexus必須具有有效路由才能將流量轉發到此IP。可以配置NAT清單末尾的「增加路由」手動靜態路由條目。Nexus自動生成指向已轉換IP的路由,該路由指向未轉換IP的下一跳。
驗證IP內部全局轉換
N9K1 |
N9K2 |
N9K3 |
ethanalyzer local interface inband display-filter icmp limit-captured-frames 0
Capturing on inband
1 2023-09-09 00:34:03.617811110 10.3.3.3 → 10.1.1.1 ICMP 158 Echo (ping) request id=0xd923, seq=0/0, ttl=254
|
sh ip nat translations
Pro Inside global Inside local Outside local Outside global
any 192.168.1.1 10.1.1.1 --- ---
show ip route 192.168.1.1
192.168.1.1/32, ubest/mbest: 1/0
via 10.10.10.10 [1/0], 00:48:06, NAT
|
HOST2# ping 192.168.1.1 source 10.3.3.3
PING 192.168.1.1 (192.168.1.1) from 10.3.3.3: 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=253 time=1.175 ms
|
N9K1收到發往10.1.1.1的轉換資料包。 |
N9K2將內部本地IP (192.168.1.1)轉換為內部全局IP (10.1.1.1)。 使用命令「add route」可自動生成通往轉換路由的路由 由於nexus僅具有內部配置,因此nexus僅顯示內部資訊。 |
N9K2對內部本地ip 192.168.1.1發起ping操作。 |
配置從全局外部IP的轉換
外部全局IP:10.3.3.3
外部本地IP:172.16.3.3
N9K1 |
N9K2 |
N9K3 |
interface Ethernet1/1
ip address 10.10.10.11/24
no shut
interface loopback 0
ip address 10.1.1.1/32
ip route 0.0.0.0/0 10.10.10.11
|
feature nat
ip access-list tac-nat-outside
permit ip host 10.3.3.3 any
ip nat pool tac-nat-outisde-pool 172.16.3.3 172.16.3.3 prefix-length 32
ip nat outside source list tac-nat-outside pool tac-nat-outisde-pool dynamic add-route
interface Ethernet1/1
ip nat inside
ip address 10.10.10.11/24
no shut
interface Ethernet1/2
ip nat outside
ip address 10.20.20.21/24
no shut
ip route 10.3.3.3/32 10.20.20.20
ip route 10.1.1.1/32 10.10.10.10
|
interface Ethernet1/2
ip address 10.20.20.20/24
no shut
interface loopback 0
ip address 10.3.3.3/32
ip route 0.0.0.0/0 10.20.20.21
|
注意:由於IP 172.16.3.3不存在於任何裝置上,因此nexus必須具有有效路由才能將流量轉發到此IP。可以配置NAT清單末尾的「增加路由」手動靜態路由條目。Nexus自動生成指向已轉換IP的路由,該路由指向未轉換IP的下一跳。
驗證從全局外部IP進行的轉換
N9K1 |
N9K2 |
N9K3 |
ping 172.16.3.3 source 10.1.1.1
PING 172.16.3.3 (172.16.3.3) from 10.1.1.1: 56 data bytes
64 bytes from 172.16.3.3: icmp_seq=0 ttl=253 time=1.103 ms
|
sh ip nat translations
Pro Inside global Inside local Outside local Outside global
any --- --- 172.16.3.3 10.3.3.3
show ip route 172.16.3.3
172.16.3.3/32, ubest/mbest: 1/0
via 10.20.20.20 [1/0], 00:48:06, NAT
|
ethanalyzer local interface inband display-filter icmp limit-captured-frames 0
Capturing on 'ps-inb'
1 2023-09-09 00:34:03.617811110 10.1.1.1 → 10.3.3.3 ICMP 158 Echo (ping) request id=0xd923, seq=0/0, ttl=254
|
N9K1發起對外部本地ip 172.16.3.3的ping。 |
N9K2將外部本地IP (192.168.3.3)轉換為外部全局IP (10.3.3.3)。 使用命令「add route」可自動生成通往轉換路由的路由 由於nexus只有外部配置,因此nexus僅顯示外部資訊。 |
N9K3收到發往10.3.3.3的轉換資料包。 |
配置轉換全局內部/外部IP(兩次Nat)
外部全局IP:10.3.3.3
外部本地IP:172.16.3.3
內部全局IP:10.1.1.1
內部本地IP:192.168.1.1
N9K1 |
N9K2 |
N9K3 |
interface Ethernet1/1
ip address 10.10.10.11/24
no shut
interface loopback 0
ip address 10.1.1.1/32
ip route 0.0.0.0/0 10.10.10.11
|
feature nat
ip access-list tac-nat-outside
permit ip host 10.3.3.3 any
ip access-list tac-nat-inside
permit ip host 10.1.1.1 any
For Outside Twice translation nexus need 2 source list, one static Inside and one Dynamic Outside.
Both of them needs to match the same group.
ip nat pool tac-nat-outisde-pool 172.16.3.3 172.16.3.3 prefix-length 32
ip nat outside source list tac-nat-outside pool tac-nat-outisde-pool group 2 dynamic add-route
ip nat inside source static 10.1.1.1 192.168.1.1 group 2 dynamic add-route
For Inside Twice translation nexus need 2 source list, one static Outside and one Dynamic Inside.
Both of them needs to match the same group.
ip nat pool tac-nat-inside-pool 192.168.1.1 192.168.1.1 prefix-length 32
ip nat inside source list tac-nat-inside pool tac-nat-inside-pool group 1 dynamic add-route
ip nat outside source static 10.3.3.3 172.16.3.3 group 1 dynamic add-route
interface Ethernet1/1
ip nat inside
ip address 10.10.10.11/24
no shut
interface Ethernet1/2
ip nat outside
ip address 10.20.20.21/24
no shut
ip route 10.3.3.3/32 10.20.20.20
ip route 10.1.1.1/32 10.10.10.10
|
interface Ethernet1/2
ip address 10.20.20.20/24
no shut
interface loopback 0
ip address 10.3.3.3/32
ip route 0.0.0.0/0 10.20.20.21
|
注意:由於IP 172.16.3.3和192.168.1.1不存在於任何裝置的物理上,因此nexus必須具有有效路由才能將流量轉發到此IP。可以配置NAT清單末尾的「增加路由」手動靜態路由條目。Nexus自動生成指向已轉換IP的路由,該路由指向未轉換IP的下一跳。
驗證轉換全局內部/外部IP(兩次Nat)
N9K1 |
N9K2 |
N9K3 |
ethanalyzer local interface inband display-filter icmp limit-captured-frames 0
Capturing on inband
1 2023-09-09 00:34:03.617811110 172.16.3.3 → 10.1.1.1 ICMP 158 Echo (ping) request id=0xd923, seq=0/0, ttl=254
|
sh ip nat translations
Pro Inside global Inside local Outside local Outside global
icmp 192.168.1.1:0 10.1.1.1:0 172.16.3.3:37734 10.3.3.3:37734
show ip route 192.168.1.1
192.168.1.1/32, ubest/mbest: 1/0
via 10.10.10.10 [1/0], 00:48:06, NAT
show ip route 172.16.3.3
172.16.3.3/32, ubest/mbest: 1/0
via 10.20.20.20 [1/0], 00:48:06, NAT
|
HOST2# ping 192.168.1.1 source 10.3.3.3
PING 192.168.1.1 (192.168.1.1) from 10.3.3.3: 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=253 time=1.175 ms
|
N9K1收到目標為10.1.1.1(這是您尋找快取缺失可以使用的隱藏資料包)。 |
N9K2將內部本地IP (192.168.1.1)轉換為內部全局IP (10.1.1.1)。 N9K2將外部本地IP (192.168.3.3)轉換為外部全局IP (10.3.3.3)。 使用命令「add route」可自動生成通往轉換路由的路由 由於nexus僅具有內部配置,因此nexus僅顯示內部資訊。 |
N9K2對內部本地ip 192.168.1.1發起ping操作。 |