实验目的

  1. 理解静态NAT的转换原理
  2. 掌握静态NAT的配置方法

实验拓扑

实验需求

  1. 根据实验拓扑图,完成设备的基本配置;
  2. 在R2上创建Loopback0接口,IP地址是9.2.6.7/32,模拟公网上的一台服务器;
  3. 在R1上配置静态NAT,PC1访问服务器使用12.1.1.11转换源地址;
  4. 在R1上配置静态NAT,PC2访问服务器使用12.1.1.12转换源地址。

实验步骤

步骤1:设备的基本配置

配置PC1:

Router>enable

Router#configure terminal

Router(config)#hostname PC1

PC1(config)#no ip routing

PC1(config)#ip default-gateway 192.168.1.254

PC1(config)#interface ethernet0/0

PC1(config-if)#ip address 192.168.1.1 255.255.255.0

PC1(config-if)#no shutdown

PC1(config-if)#end

PC1#

配置PC2:

Router>enable

Router#configure terminal

Router(config)#hostname PC2

PC2(config)#no ip routing

PC2(config)#ip default-gateway 192.168.1.254

PC2(config)#interface ethernet0/0

PC2(config-if)#ip address 192.168.1.2 255.255.255.0

PC2(config-if)#no shutdown

PC2(config-if)#end

PC2#

配置SW1:

Switch>ena

Switch#conf t

Switch(config)#no ip domain-lookup

Switch(config)#line console 0

Switch(config-line)# logging s

Switch(config-line)# exec-t 0 0

Switch(config-line)# exit

Switch(config)#hostname SW1

SW1(config)#end

SW1#

配置R1:

Router>enable

Router#configure terminal

Router(config)#hostname R1

R1(config)#no ip domain-lookup

R1(config)#line console 0

R1(config-line)#exec-timeout 0 0

R1(config-line)#logging synchronous

R1(config-line)#exit

R1(config)#interface ethernet0/0

R1(config-if)#ip address 192.168.1.254 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#exit

R1(config)#interface ethernet0/1

R1(config-if)#ip address 12.1.1.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#end

R1#

配置R2:

Router>enable

Router#configure terminal

Router(config)#hostname R2

R2(config)#no ip domain-lookup

R2(config)#line console 0

R2(config-line)#exec-timeout 0 0

R2(config-line)#logging synchronous

R2(config-line)#exit

R2(config)#interface loopback0

R2(config-if)#ip address 9.2.6.7 255.255.255.255

R2(config-if)#exit

R2(config)#interface ethernet0/0

R2(config-if)#ip address 12.1.1.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#end

R2#

步骤2:配置静态NAT

配置R1:

R1(config)#ip nat inside source static 192.168.1.1 12.1.1.11 //配置静态转换

R1(config)#ip nat inside source static 192.168.1.2 12.1.1.12 //配置静态转换

R1(config)#interface ethernet 0/0

R1(config-if)#ip nat inside //指定inside接口

R1(config-if)#exit

R1(config)#interface ethernet 0/1

R1(config-if)#ip nat outside //指定outside接口

R1(config-if)#exit

R1(config)#ip route 0.0.0.0 0.0.0.0 12.1.1.2 //配置到达公网的默认路由

R1(config)#end

R1#

检查R1的NAT表项:

R1#show ip nat translations

Pro Inside global Inside local Outside local Outside global

--- 12.1.1.11 192.168.1.1 --- ---

--- 12.1.1.12 192.168.1.2 --- ---

R1的NAT映射表创建了两个静态NAT条目。

测试PC1访问服务器:

PC1#ping 9.2.6.7

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 9.2.6.7, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

测试PC2访问服务器:

PC2#ping 9.2.6.7

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 9.2.6.7, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

检查R1的NAT表项:

R1#sh ip nat translations

Pro Inside global Inside local Outside local Outside global

icmp 12.1.1.11:4 192.168.1.1:4 9.2.6.7:4 9.2.6.7:4

--- 12.1.1.11 192.168.1.1 --- ---

icmp 12.1.1.12:2 192.168.1.2:2 9.2.6.7:2 9.2.6.7:2

--- 12.1.1.12 192.168.1.2 --- ---


微思郭仔
31 声望2 粉丝

微思IT认证培训-思科、华为、红帽、oracle、VMware、PMP、CISP等,一切为了成为更好的自己,加油!!!