在下面的网络拓扑图中,两台路由器间通过串口相连,模拟Internet环境。通过在R1上配置动态NAT,让内网上的两台PC都能够访问外网资源。在该实验中,路由器型号为C3745,软件为GNS3-2.2.5。

R1#conf t
R1(config)#inter f0/0
R1(config-if)#ip add 192.34.1.254 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
R1(config)#inter s1/0
R1(config-if)#encapsulation ppp
R1(config-if)#ip add 200.34.1.1 255.255.255.240
R1(config-if)#no shut
R1(config-if)#exit
//配置默认路由,将路由器R1上所有访问Internet的数据发送到路由器R2上。
R1(config)#ip route 0.0.0.0 0.0.0.0 200.34.1.2
//创建地址池global-pool,地址池的IP地址范围为200.34.1.3-200.34.1.10,掩码为255.255.255.240
R1(config)#ip nat pool global-pool 200.34.1.3 200.34.1.10 netmask 255.255.255.240
//创建标准ACL,允许内部本地IP地址192.34.1.0/24转换为内部全局地址。
R1(config)#access-list 1 permit 192.34.1.0 0.0.0.255
//在全局配置下配置动态NAT,将内部本地地址192.34.1.0/24转换为内部全局地址200.34.1.3-200.34.1.10
R1(config)#ip nat inside source list 1 pool global-pool
//配置F0/0端口为内部端口
R1(config)#inter f0/0
R1(config-if)#ip nat inside
R1(config-if)#exit
//配置S1/0端口为外部端口
R1(config)#inter s1/0
R1(config-if)#ip nat outside
R1(config-if)#exit
R1(config)#
R2#conf t
R2(config)#inter f0/0
R2(config-if)#ip add 192.34.2.254 255.255.255.0
R2(config-if)#no shut
R2(config-if)#exit
R2(config)#inter s1/0
R2(config-if)#encapsulation ppp
R2(config-if)#ip add 200.34.1.2 255.255.255.240
R2(config-if)#no shut
R2(config-if)#exit
给交换机SW1下的PC都配置相应的IP地址,然后PC1访问PC3。
PC1> ping 192.34.2.1
84 bytes from 192.34.2.1 icmp_seq=1 ttl=62 time=49.956 ms
84 bytes from 192.34.2.1 icmp_seq=2 ttl=62 time=35.375 ms
84 bytes from 192.34.2.1 icmp_seq=3 ttl=62 time=35.397 ms
84 bytes from 192.34.2.1 icmp_seq=4 ttl=62 time=35.403 ms
84 bytes from 192.34.2.1 icmp_seq=5 ttl=62 time=35.386 ms
PC1>
查看NAT转换表。
R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
icmp 200.34.1.3:46592 192.34.1.1:46592 192.34.2.1:46592 192.34.2.1:46592
icmp 200.34.1.3:47104 192.34.1.1:47104 192.34.2.1:47104 192.34.2.1:47104
icmp 200.34.1.3:47616 192.34.1.1:47616 192.34.2.1:47616 192.34.2.1:47616
icmp 200.34.1.3:47872 192.34.1.1:47872 192.34.2.1:47872 192.34.2.1:47872
icmp 200.34.1.3:48128 192.34.1.1:48128 192.34.2.1:48128 192.34.2.1:48128
icmp 200.34.1.3:48640 192.34.1.1:48640 192.34.2.1:48640 192.34.2.1:48640
icmp 200.34.1.3:48896 192.34.1.1:48896 192.34.2.1:48896 192.34.2.1:48896
icmp 200.34.1.3:49152 192.34.1.1:49152 192.34.2.1:49152 192.34.2.1:49152
icmp 200.34.1.3:49408 192.34.1.1:49408 192.34.2.1:49408 192.34.2.1:49408
icmp 200.34.1.3:49664 192.34.1.1:49664 192.34.2.1:49664 192.34.2.1:49664
--- 200.34.1.3 192.34.1.1 --- ---
R1#
其中,IP地址冒号后的数字表示端口号,动态NAT地址转换配置完成。