简介
本文档介绍如何配置和验证网络地址转换(NAT)和两次NAT。
先决条件
要求
思科建议您了解以下主题:
使用的组件
名称 |
平台 |
version |
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发起ping到内部本地ip 192.168.1.1。 |
配置从全局外部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发起ping到内部本地ip 192.168.1.1。 |