2.6-NAT

2.6NAT
    网络地址转换协议NAT(Network Address Translation):
    交换和远程都要用,先上什么就放在哪一块讲,具体来说NAT还是属于远程的。
 
    NAT的三组概念:
 
----------------------------------------------------------------------------
 
   LAB1:NAT的基本配置(原理性的NAT):
    STEP1:按图构建拓朴:
    R2/R4配置为PC模拟用户,R5的环回路口模拟公网;宣告RIP网络时不宣告192.168.1.0/24网段,这是因为现实中私网地址是不会被宣告到公网中的;R5可以宣告所有,公网的边界路由器R3上则宣告35.0.0.0/24网段和13.0.0.3/24接口
    STEP2:在私网的边缘路由器上做指向公网的默认静态路由:
    R1(c)#ip route 0.0.0.0 0.0.0.0 serial 1 ;
    STEP3:在PC上指定网关:
    (c)#ip default-gateway 192.168.1.1然后Ping确认能与网关通讯;这个时候PC2/PC4能够将包发往R5,但是R5上没有到PC2/PC4的路由(没有宣告)所以无法回包;现实中的ISP会在路由器上做ACL将私网地址过滤掉,所以PC2/PC4的包也不能到R5;
    STEP4:在公网边界路由器配置ACL过滤私网地址:
    首先过滤私网地址:(c)#access-list 1 deny 10.0.0.0 0.255.255.255 →access-list 1 deny 192.168.0.0 0.0.255.255→access-list 1 deny 172.16.0.0 0.15.255.255 →access-list 1 permit any any →int s0(在ISP连接用户的路由器接口上调用) →ip access-group 1 in ;
    然后允许ISP卖出的地址连入:(c)#access-list 13 permit 13.0.0.0 →router-map R-13 permit 10 →match ip add 13 →set metric 1 →router rip(要重分布)→redistribute connected route-map R-13 ;
    STEP5:配置NAT:
    注意实验需求要在私网边界内口关闭ARP:(c)#int e0 →no ip proxy-arp ;
    然后配置NAT的内/外口:(c-i)#ip nat inside/outside ;
    接着配置NAT地址转换公网地址:(c)#ip nat inside(我方) source(所发起的) static 192.168.1.2(私网地址) 13.0.0.10(公网地址);
    STEP6:一些查看命令:
    R1#show ip nat translations(察看NAT的转换表);
    R1#debug ip nat (察看NAT的转换过程)的结果:
    发送:s=192.l68.1.2->13.0.0.10 d=5.5.5.5 ;
    接收:s=5.5.5.5 d=13.0.0.10->192.168.1.2 ;
    结论:静态NAT不实用,PC4也要做NAT,如果用户多的话,要购买相当多的NAT公网地址。
 
----------------------------------------------------------------------------
 
   LAB2:中小型企业通常使用基于接口的端口复用(Overload):
    STEP1:定义NAT的外口/内口:
    ……(同LAB1);
    STEP2:通过ACL,定义准备进行NAT的内网的用户群:
    (c)#access-list 1 permit 192.168.1.0 0.0.0.255 ;
    STEP3:进行基于接口的NAT端口复用:
    (c)#ip nat inside source list 1(通过ACL指定内网用户) interface serial 1(NAT外口) overload(端口复用:新IOS里面默认启用) ;
    测试:实现了192.168.1.*整个网段的用户共享一个IP地址连接到Internet。
 
----------------------------------------------------------------------------
 
   LAB3:使用Route-Map做基于接口的端口复用:
    STEP1:定义NAT的外口/内口,定义内网用户群:
    ……(同LAB2);
    STEP2:使用Route-map调用ACL:
    (c)#route-map X →match ip address 1 ;
    STEP3:进行基于接口的NAT端口复用:
    (c)#ip nat inside source route-map X interface serial 1 overload ;
    测试:实现了192.168.1.*整个网段的用户共享一个IP地址连接到Internet。
 
----------------------------------------------------------------------------
 
   LAB4:大型企业用较多的公网IP利用POOL对不同的部门进行NAT转换:
    STEP1:构建拓朴并定义NAT的外口/内口:
    修改IP后……(同LAB3);
    STEP2:通过ACL,定义准备进行NAT的内网的用户群:
    (c)#access-list 10 permit 192.168.10.0 0.0.0.255 →access-list 20 permit 192.168.20.0 0.0.0.255 ;
    STEP3:在PC上指定网关:
    实际工作中不需要此步,但是实验中为了更全面的了解课程内容所以关闭了ARP就要配了;
    首先为各个网段配置同一网段的网关IP,可以使用secondaryIP或者子接口配置:(c)#in e0 →ip add 192.168.10.1 255.255.255.0 →ip add 192.168.20.1 255.255.255.0 secondary ;
    然后在PC设定网关:(c)#ip default-gateway 网关IP ;注意养成好习惯:PC2/PC4都要测试能否ping通自己的网关!!!!!
    STEP5:在私网边界路由器将从ISP买到的公网IP放入地址池(pool):
    掩码可以使用两种格式,这是等价的:(c)#ip nat pool PL-A 13.0.0.8(起始IP) 13.0.0.11(终止IPprefix-length 24/netmask 255.255.255.0(IP长度:ISP给定) →ip nat pool PL-B 13.0.0.12 13.0.0.0.15 prefix-length 24 ;
    STEP6:为不同的部门进行基于不同POOL的NAT转换:
    (c)#ip nat inside source list 10 pool PL-A overload →ip nat inside source list 20 pool PL-B overload ;
    然后可以用一些命令查看:R1#sh ip nat translation ;
    STEP7:在公网边界路由器的操作:
    为了让R5有回包路由,在R3上重分布静态路由到RIP中:
    (c)#ip route 100.0.0.0 255.255.255.248 13.0.0.1 (定义静态路由)→ip prefix-list 100 permit 100.0.0.8/29 →route-map R-100 →match ip add prefix-list 100 →set metric 1 (定义重分布的范围)→route rip →redistribute static route-map R-100 (重分布);
    然后观察:R5#sh ip route rip可读到100.0.0.8/29 。
 
----------------------------------------------------------------------------
 
   LAB5:通过NAT实现镜像服务器的负载均衡(实际工程少用→了解即可):
    STEP1:定义NAT外口/内口:
    同LAB4;实验需求:公网上能访问这两台服务器,而且负载均衡地到PC2/4;
    STEP2:通过ACL定义我方公网地址成为来自外网访问的目标地址:
    (c)#access-list 10 permit 13.0.0.10 0.0.0.0(精确匹配,只转换一个地址);
    STEP3:定义内网服务器群的地址池:
    (c)#ip nat pool pl 192.168.10.2 192.168.10.3 prefix-length 24 type rotary(轮转类型) ;
    STEP4:定义NAT:
    (c)#ip nat inside destination list 10 pool pl ;
    STEP5:为了实验目的:
    PC上:(c)#linvty 0 4 no login (不需要密码就可以被TELNET→危险→现实请谨慎);
    然后在R5上:(c)#telnet 13.0.0.10 可以看到是轮流的。
 
----------------------------------------------------------------------------
 
   LAB6:使用一个接口的公网IP对外提供多个不同的服务器:
    STEP1:定义NAT外口/内口:
    同LAB5;注意:静态的TCP端口映射,静态的端口复用;
    拓朴使用一个接口的公网IP对外网提供多个不同的服务器:如果你向访问我的FTP(TCP10000号端口或21口)或者WWW服务器(20000号端口或80口);
    STEP2:在私网边界路由器构建服务器:
    FTP服务器:(c)#ip nat inside source static tcp 192.168.10.2 21 13.0.0.1 21 ;
    WWW服务器:(c)#ip nat inside source static tcp 192.168.10.4 80 13.0.0.1 80 ;
    ∵没有服务器∴实验中无法达成;
    实验中可以把私网端口改为23号端口代替(公网端口不要改):
    FTP服务器:(c)#ip nat inside source static tcp 192.168.10.2 23 13.0.0.1 21 ;
    WWW服务器:(c)#ip nat inside source static tcp 192.168.10.4 23 13.0.0.1 80 ;
    R1:(c)#line vty 0 4 →no login ;
    R5:(c)#TELNET 13.0.0.1(进入了R1,无端口号) →telnet 13.0.0.1 21 (进入了FTP服务器) →telnet 13.0.0.1 80 (进入了WWW服务器);
     
 
r1(config)#do sh run
Building configuration...
 
Current configuration : 737 bytes
!
version 12.2
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname r1
!
logging queue-limit 100
!
ip subnet-zero
no ip domain lookup
!
!
!
!
interface Ethernet0
 ip address 10.1.1.1 255.255.255.0
 ip nat inside
!
interface Serial0
 no ip address
 shutdown
!
interface Serial1
 ip address 13.1.1.1 255.255.255.0
 ip nat outside
!
ip nat inside source list 1 interface Serial1 overload
no ip http server
ip classless
ip route 192.168.1.0 255.255.255.0 Serial0
ip route 192.168.1.0 255.255.255.0 Serial1
!
!
!
access-list 1 permit 2.2.2.0 0.0.0.255
access-list 1 permit 10.1.1.0 0.0.0.255
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
 
 
 
静态NAT配置
ip nat inside static source-IP des-IP
指定什么端口是inside什么是outside
int e 0
ip nat inside
int s 0
ip nat outside
 
动态NAT配置
#ip nat pool "name" "start-ip" "end-ip"(只有公网地址作池才有意义)mask x.x.x.x
access-list "access-list-number" permit source [source-wildcard]
ip nat inside source list
example:
ip nat pool ccna 12.1.1.4 12.1.1.5 mask 255.255.255.0
ip access-list standard NAT
r1(config-std-nacl)permit 10.1.1.4 0.0.0.1
ip nat inside source list NAT POOL CCNA
clear ip nat translations * 清空nat表,让地址池重置
 
Overloading端口复用PAT--主流应用
router(config)#access-list access-list-number permit source source-wildcard
ip nat source list NAT interface serial 0 overload
sh ip nat translation
 
 
sh ver:35
Switch#sh ver
Cisco IOS Software, C3550 Software (C3550-IPSERVICESK9-M), Version 12.2(25)SEE1, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Mon 22-May-06 08:08 by yenanh
Image text-base: 0x00003000, data-base: 0x00DC0370
 
ROM: Bootstrap program is C3550 boot loader
 
Switch uptime is 5 minutes
System returned to ROM by power-on
System image file is "flash:/c3550-ipservicesk9-mz.122-25.SEE1.bin"
 
 
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
 
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
 
If you require further assistance please contact us by sending email to
export@cisco.com.
 
Cisco WS-C3550-48 (PowerPC) processor (revision H0) with 65526K/8192K bytes of memory.
Processor board ID CAT0733Z2K3
Last reset from warm-reset
Running Layer2/3 Switching Image
 
Ethernet-controller 1 has 12 Fast Ethernet/IEEE 802.3 interfaces
 
Ethernet-controller 2 has 12 Fast Ethernet/IEEE 802.3 interfaces
 
Ethernet-controller 3 has 12 Fast Ethernet/IEEE 802.3 interfaces
 
Ethernet-controller 4 has 12 Fast Ethernet/IEEE 802.3 interfaces
 
Ethernet-controller 5 has 1 Gigabit Ethernet/IEEE 802.3 interface
 
Ethernet-controller 6 has 1 Gigabit Ethernet/IEEE 802.3 interface
 
48 FastEthernet interfaces
2 Gigabit Ethernet interfaces
 
The password-recovery mechanism is enabled.
384K bytes of flash-simulated NVRAM.
Base ethernet MAC Address: 00:0D:BD:CF:FA:00
Motherboard assembly number: 73-5701-09
Power supply part number: 34-0967-01
Motherboard serial number: CAT07330AHT
Power supply serial number: DTH07310QPW
Model revision number: H0
Motherboard revision number: A0
Model number: WS-C3550-48-SMI
System serial number: CAT0733Z2K3
Configuration register is 0x10F
 
 
sh ver:29
Switch(config)#do sh ver
Cisco Internetwork Operating System Software 
IOS (tm) C2950 Software (C2950-I6K2L2Q4-M), Version 12.1(22)EA10, RELEASE SOFTWARE (fc2)
Copyright (c) 1986-2007 by cisco Systems, Inc.
Compiled Tue 08-May-07 12:18 by myl
Image text-base: 0x80010000, data-base: 0x8067C000
 
ROM: Bootstrap program is C2950 boot loader
 
Switch uptime is 9 minutes
System returned to ROM by power-on
System image file is "flash:/c2950-i6k2l2q4-mz.121-22.EA10.bin"
 
 
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
 
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
 
If you require further assistance please contact us by sending email to
export@cisco.com.
 
cisco WS-C2950-24 (RC32300) processor (revision J0) with 19925K bytes of memory.
Processor board ID FOC0822S11E
Last reset from system-reset
Running Standard Image
24 FastEthernet/IEEE 802.3 interface(s)
 
32K bytes of flash-simulated non-volatile configuration memory.
Base ethernet MAC Address: 00:0D:28:61:62:00
Motherboard assembly number: 73-5781-11
Power supply part number: 34-0965-01
Motherboard serial number: FOC06500G8M
Power supply serial number: PHI071900ED
Model revision number: J0
Motherboard revision number: A0
Model number: WS-C2950-24
System serial number: FOC0822S11E
Configuration register is 0xF
 



来自为知笔记(Wiz)



posted on 2016-12-10 11:09  sanyuanyanjin  阅读(362)  评论(0编辑  收藏  举报