案例配置拓扑
案例配置需求
1、 互联IP为XY.1.1.X/24,Loopback 0的IP为X.X.X.X,其中X为本设备ID,Y为对端设备ID;
2、 三台路由器使用OSPF进行IGP通信(发布设备的Loopback 0和物理接口);
3、 在R3上配置NAT,使得R1和R5的Loopback 1可以互访;
4、 只允许在R1、R2、R4、R5上各添加一条静态路由实现需求;
案例配置思路
1、 在5台路由器上配置IP
R1(config)#interface fastEthernet 0/1
R1(config-if)#ip address 12.1.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#interface loopback 0
R1(config-if)#ip address 1.1.1.1 255.255.255.0
R1(config-if)#interface loopback 1
R1(config-if)#ip address 11.11.11.11 255.255.255.0
R2(config)#interface fastEthernet 0/0
R2(config-if)#ip address 12.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#interface fastEthernet 0/1
R2(config-if)#ip address 23.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#int lo0
R2(config-if)#ip address 2.2.2.2 255.255.255.0
R3(config)#interface fastEthernet 0/0
R3(config-if)#ip address 23.1.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#interface fastEthernet 0/1
R3(config-if)#ip address 34.1.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#int lo0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R4(config)#interface fastEthernet 0/0
R4(config-if)#ip address 34.1.1.4 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#interface fastEthernet 0/1
R4(config-if)#ip address 45.1.1.4 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#int lo0
R4(config-if)#ip address 4.4.4.4 255.255.255.0
R5(config)#interface fastEthernet 0/0
R5(config-if)#ip address 45.1.1.5 255.255.255.0
R5(config-if)#no shutdown
R5(config-if)#interface loopback 0
R5(config-if)#ip address 5.5.5.5 255.255.255.0
R5(config-if)#interface loopback 1
R5(config-if)#ip address 55.55.55.55 255.255.255.0
2、 在5台路由器上配置OSPF,发布直连接口和Loopback 0;
R1(config)#router ospf 100
R1(config-router)#router-id 91.1.1.1
R1(config-router)#network 12.1.1.0 0.0.0.255 area 0
R1(config-router)#network 1.1.1.0 0.0.0.255 area 0
R2(config)#router ospf 100
R2(config-router)#router-id 92.2.2.2
R2(config-router)#network 12.1.1.0 0.0.0.255 area 0
R2(config-router)#network 23.1.1.0 0.0.0.255 area 0
R2(config-router)#network 2.2.2.0 0.0.0.255 area 0
R3(config)#router ospf 100
R3(config-router)#router-id 93.3.3.3
R3(config-router)#network 34.1.1.0 0.0.0.255 area 0
R3(config-router)#network 23.1.1.0 0.0.0.255 area 0
R3(config-router)#network 3.3.3.0 0.0.0.255 area 0
R4(config)#router ospf 100
R4(config-router)#router-id 94.4.4.4
R4(config-router)#network 34.1.1.0 0.0.0.255 area 0
R4(config-router)#network 45.1.1.0 0.0.0.255 area 0
R4(config-router)#network 4.4.4.0 0.0.0.255 area 0
R5(config)#router ospf 100
R5(config-router)#router-id 95.5.5.5
R5(config-router)#network 45.1.1.0 0.0.0.255 area 0
R5(config-router)#network 5.5.5.0 0.0.0.255 area 0
3、 在四台路由器上配置静态路由,引导数据
ip route 55.55.55.0 255.255.255.0 12.1.1.2 /在R1上设置去往55.55.55.55的下一跳/
ip route 55.55.55.0 255.255.255.0 23.1.1.3 /在R2上设置去往55.55.55.55的下一跳/
ip route 11.11.11.0 255.255.255.0 45.1.1.4 /在R5上设置去往11.11.11.11的下一跳/
ip route 11.11.11.0 255.255.255.0 34.1.1.3 /在R4上设置去往11.11.11.11的下一跳/
4、 在R3上配置NAT,实现R1和R5的Loopback 1互访:
interface FastEthernet0/0
ip nat outside /设置接口为NAT出接口/
interface FastEthernet0/1
ip nat outside /设置接口为NAT出接口/
ip nat inside source static 1.1.1.1 11.11.11.11
/设置静态NAT,将源为1.1.1.1的数据包的源转换为11.11.11.11 /
ip nat inside source static 5.5.5.5 55.55.55.55
案例检验结果
1、 配置完成后,在R3上查看NAT转换表:
2、 在R1和R5上开启ICMP的debug后,用R1的Loopback 1访问R5的Loopback 1:
案例总结及其它
1、 静态NAT配置完成后,会直接在设备上生成NAT转换表;
2、 当有数据从该设备的NAT outside接口进入时,会优先用该数据的目的地址和转换表中的Inside global地址进行匹配,当匹配成功时,该数据的目的地址会被替换为对应条目的Inside local地址,这个过程被称为NAT反向路径查询;
3、 本实验使用来回2次的NAT反向路径查询,将原本55.55.55.55到11.11.11.11的通信,转换为5.5.5.5到1.1.1.1的通信;